-
Notifications
You must be signed in to change notification settings - Fork 221
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
}); |