-
Notifications
You must be signed in to change notification settings - Fork 219
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
5 changed files
with
497 additions
and
37 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,54 @@ | ||
<button id="start">start</button><button id="add">Add</button> | ||
<pre id="output"></pre> | ||
<script type="module"> | ||
import { PGlite } from "../dist/index.js"; | ||
import { live } from "../dist/live/index.js"; | ||
|
||
const output = document.getElementById("output"); | ||
const startBtn = document.getElementById("start"); | ||
const addBtn = document.getElementById("add"); | ||
let counter = 1000; | ||
let lastClicked = 0; | ||
const nameLength = 10000; | ||
const nameSuffix = "-".repeat(nameLength); | ||
|
||
const pg = new PGlite({ | ||
extensions: { | ||
live, | ||
}, | ||
}); | ||
window.pg = pg; | ||
|
||
await pg.exec(` | ||
CREATE TABLE IF NOT EXISTS test ( | ||
id SERIAL PRIMARY KEY, | ||
rand float, | ||
name TEXT | ||
); | ||
INSERT INTO test (name, rand) | ||
SELECT 'test' || i || '${nameSuffix}', random() | ||
FROM generate_series(1, ${counter}) AS i; | ||
`); | ||
|
||
startBtn.addEventListener("click", async () => { | ||
lastClicked = performance.now(); | ||
pg.live.changes( | ||
"SELECT * FROM test ORDER BY rand;", | ||
null, | ||
"id", | ||
(changes) => { | ||
const time = performance.now() - lastClicked; | ||
console.log(`Update took ${time}ms`); | ||
output.textContent = JSON.stringify(changes, null, 2); | ||
} | ||
); | ||
}); | ||
|
||
addBtn.addEventListener("click", async () => { | ||
lastClicked = performance.now(); | ||
await pg.query( | ||
"INSERT INTO test (name, rand) VALUES ($1, random());", | ||
[`test${++counter}${nameSuffix}`] | ||
); | ||
}); | ||
</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,54 @@ | ||
<button id="start">start</button><button id="add">Add</button> | ||
<div id="output"></div> | ||
<script type="module"> | ||
import { PGlite } from "../dist/index.js"; | ||
import { live } from "../dist/live/index.js"; | ||
|
||
const output = document.getElementById("output"); | ||
const startBtn = document.getElementById("start"); | ||
const addBtn = document.getElementById("add"); | ||
let counter = 1000; | ||
let lastClicked = 0; | ||
const nameLength = 10000; | ||
const nameSuffix = "-".repeat(nameLength); | ||
|
||
const pg = new PGlite({ | ||
extensions: { | ||
live, | ||
}, | ||
}); | ||
window.pg = pg; | ||
|
||
await pg.exec(` | ||
CREATE TABLE IF NOT EXISTS test ( | ||
id SERIAL PRIMARY KEY, | ||
rand FLOAT, | ||
name TEXT | ||
); | ||
INSERT INTO test (name, rand) | ||
SELECT 'test' || i || '${nameSuffix}', random() | ||
FROM generate_series(1, ${counter}) AS i; | ||
`); | ||
|
||
startBtn.addEventListener("click", async () => { | ||
lastClicked = performance.now(); | ||
pg.live.incrementalQuery( | ||
"SELECT * FROM test ORDER BY rand;", | ||
null, | ||
"id", | ||
(res) => { | ||
const time = performance.now() - lastClicked; | ||
console.log(`Update took ${time}ms`); | ||
output.textContent = res.rows.map((row) => row.id).join(", "); | ||
} | ||
); | ||
}); | ||
|
||
addBtn.addEventListener("click", async () => { | ||
lastClicked = performance.now(); | ||
await pg.query( | ||
"INSERT INTO test (name, rand) VALUES ($1, random());", | ||
[`test${++counter}${nameSuffix}`] | ||
); | ||
}); | ||
</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
Oops, something went wrong.