Skip to content

Commit

Permalink
contrib/uuid_ossp
Browse files Browse the repository at this point in the history
  • Loading branch information
samwillis committed Aug 1, 2024
1 parent a3e1e16 commit c328b19
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
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");
});

0 comments on commit c328b19

Please sign in to comment.