Skip to content

Commit

Permalink
contrib/uuid_ossp (#136)
Browse files Browse the repository at this point in the history
* contrib/uuid_ossp

* test build with new sdk

* forgot pg option again !

---------

Co-authored-by: pmp-p <mail.peny@free.fr>
  • Loading branch information
samwillis and pmp-p authored Aug 1, 2024
1 parent e7d96ec commit e92ac3a
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_pglite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
runs-on: ubuntu-22.04
env:
PGVERSION: 16.3
SDK_VERSION: 3.1.65.5bi
SDK_VERSION: 3.1.65.6bi
SDK_ARCHIVE: python3.12-wasm-sdk-Ubuntu-22.04.tar.lz4
SDKROOT: /opt/python-wasm-sdk
SYS_PYTHON: /usr/bin/python3
Expand Down
2 changes: 1 addition & 1 deletion cibuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ then
SKIP="\
[\
sslinfo bool_plperl hstore_plperl hstore_plpython jsonb_plperl jsonb_plpython\
ltree_plpython sepgsql bool_plperl start-scripts uuid-ossp\
ltree_plpython sepgsql bool_plperl start-scripts\
]"

for extdir in postgresql/contrib/*
Expand Down
2 changes: 1 addition & 1 deletion cibuild/pgbuild.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ CC_PGLITE=$CC_PGLITE
--disable-spinlocks --disable-atomics \
--without-zlib --disable-largefile --without-llvm \
--without-pam --disable-largefile --without-zlib --with-openssl=no \
--without-readline --without-icu \
--without-readline --without-icu --with-uuid=ossp \
${PGDEBUG}"

echo " ==== building wasm MVP:$MVP Debug=${PGDEBUG} with opts : $@ == "
Expand Down
16 changes: 16 additions & 0 deletions packages/pglite/src/contrib/uuid_ossp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type {
Extension,
ExtensionSetupResult,
PGliteInterface,
} from "../interface";

const setup = async (pg: PGliteInterface, emscriptenOpts: any) => {
return {
bundlePath: new URL("../../release/uuid-ossp.tar.gz", import.meta.url),
} satisfies ExtensionSetupResult;
};

export const uuid_ossp = {
name: "uuid-ossp",
setup,
} satisfies Extension;
101 changes: 101 additions & 0 deletions packages/pglite/tests/contrib/uuid_ossp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import test from "ava";
import { PGlite } from "../../dist/index.js";
import { uuid_ossp } from "../../dist/contrib/uuid_ossp.js";

test("uuid_ossp uuid_generate_v1", async (t) => {
const pg = new PGlite({
extensions: {
uuid_ossp,
},
});

await pg.exec('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');

const res = await pg.query("SELECT uuid_generate_v1() as value;");

t.is(res.rows[0].value.length, 36);
});

test("uuid_ossp uuid_generate_v3", async (t) => {
const pg = new PGlite({
extensions: {
uuid_ossp,
},
});

await pg.exec('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');

const res = await pg.query("SELECT uuid_generate_v3(uuid_ns_dns(), 'www.example.com') as value;");

t.is(res.rows[0].value.length, 36);
});

test("uuid_ossp uuid_generate_v4", async (t) => {
const pg = new PGlite({
extensions: {
uuid_ossp,
},
});

await pg.exec('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');

const res = await pg.query("SELECT uuid_generate_v4() as value;");

t.is(res.rows[0].value.length, 36);
});

test("uuid_ossp uuid_generate_v5", async (t) => {
const pg = new PGlite({
extensions: {
uuid_ossp,
},
});

await pg.exec('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');

const res = await pg.query("SELECT uuid_generate_v5(uuid_ns_dns(), 'www.example.com') as value;");

t.is(res.rows[0].value.length, 36);
});

test("uuid_ossp uuid_nil", async (t) => {
const pg = new PGlite({
extensions: {
uuid_ossp,
},
});

await pg.exec('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');

const res = await pg.query("SELECT uuid_nil() as value;");

t.is(res.rows[0].value, "00000000-0000-0000-0000-000000000000");
});

test("uuid_ossp uuid_ns_dns", async (t) => {
const pg = new PGlite({
extensions: {
uuid_ossp,
},
});

await pg.exec('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');

const res = await pg.query("SELECT uuid_ns_dns() as value;");

t.is(res.rows[0].value, "6ba7b810-9dad-11d1-80b4-00c04fd430c8");
});

test("uuid_ossp uuid_ns_oid", async (t) => {
const pg = new PGlite({
extensions: {
uuid_ossp,
},
});

await pg.exec('CREATE EXTENSION IF NOT EXISTS "uuid-ossp";');

const res = await pg.query("SELECT uuid_ns_oid() as value;");

t.is(res.rows[0].value, "6ba7b812-9dad-11d1-80b4-00c04fd430c8");
});

1 comment on commit e92ac3a

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.