-
Notifications
You must be signed in to change notification settings - Fork 222
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
77 changed files
with
4,744 additions
and
477 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
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
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
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
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
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
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
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,12 @@ | ||
import { PGlite } from "../dist/index.js"; | ||
import { worker } from "../dist/worker/index.js"; | ||
|
||
worker({ | ||
async init() { | ||
const pg = new PGlite("opfs-ahp://my-test-db2"); | ||
// If you want run any specific setup code for the worker process, you can do it here. | ||
return pg; | ||
}, | ||
}); | ||
|
||
console.log("Worker process started"); |
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,49 @@ | ||
<script type="module"> | ||
import { PGliteWorker } from "../dist/worker/index.js"; | ||
|
||
console.log("Starting..."); | ||
const start = performance.now(); | ||
const pg = new PGliteWorker( | ||
new Worker(new URL("./opfs-worker.js", import.meta.url), { | ||
type: "module", | ||
}) | ||
); | ||
|
||
console.log("Waiting for ready..."); | ||
await pg.waitReady; | ||
|
||
console.log("Ready! Took", performance.now() - start, "ms"); | ||
|
||
console.log("Creating table..."); | ||
await pg.exec(` | ||
CREATE TABLE IF NOT EXISTS test ( | ||
id SERIAL PRIMARY KEY, | ||
name TEXT | ||
); | ||
`); | ||
|
||
console.log("Inserting data..."); | ||
await pg.exec("INSERT INTO test (name) VALUES ('test');"); | ||
|
||
console.log("Selecting data..."); | ||
const res = await pg.exec(` | ||
SELECT * FROM test; | ||
`); | ||
|
||
console.log(res); | ||
|
||
// Transaction example: | ||
console.log("Transaction example..."); | ||
await pg.transaction(async (tx) => { | ||
await tx.exec("INSERT INTO test (name) VALUES ('test2');"); | ||
await tx.exec("INSERT INTO test (name) VALUES ('test3');"); | ||
}); | ||
|
||
console.log("Selecting data..."); | ||
const res2 = await pg.exec(` | ||
SELECT * FROM test; | ||
`); | ||
|
||
console.log(res2); | ||
|
||
</script> |
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,17 @@ | ||
import { PGlite } from "../dist/index.js"; | ||
import { worker } from "../dist/worker/index.js"; | ||
import { vector } from "../dist/vector/index.js"; | ||
|
||
worker({ | ||
async init() { | ||
const pg = new PGlite({ | ||
extensions: { | ||
vector, | ||
}, | ||
}); | ||
// If you want run any specific setup code for the worker process, you can do it here. | ||
return pg; | ||
}, | ||
}); | ||
|
||
console.log("Worker process started"); |
Oops, something went wrong.