Skip to content

Instantly share code, notes, and snippets.

@kuc-arc-f
Last active August 18, 2025 02:56
Show Gist options
  • Select an option

  • Save kuc-arc-f/669a4cc4659dbe39b6a52c4eb3047a13 to your computer and use it in GitHub Desktop.

Select an option

Save kuc-arc-f/669a4cc4659dbe39b6a52c4eb3047a13 to your computer and use it in GitHub Desktop.
pglite , example
import { PGlite } from '@electric-sql/pglite'
const db = new PGlite('./pgdata')
await db.exec(`
CREATE TABLE IF NOT EXISTS todo (
id SERIAL PRIMARY KEY,
task TEXT,
done BOOLEAN DEFAULT false
);
INSERT INTO todo (task, done) VALUES ('Install PGlite from NPM', true);
INSERT INTO todo (task, done) VALUES ('Load PGlite', true);
INSERT INTO todo (task, done) VALUES ('Create a table', true);
INSERT INTO todo (task, done) VALUES ('Insert some data', true);
INSERT INTO todo (task) VALUES ('Update a task');
`)
// SELECT
const ret = await db.query(`
SELECT * from todo;
`)
console.log(ret.rows)
import { PGlite } from '@electric-sql/pglite'
const db = new PGlite('./pgdata')
// SELECT
const ret = await db.query(`
SELECT * from todo;
`)
console.log(ret.rows)
import { PGlite } from '@electric-sql/pglite'
const run = async function(){
try{
console.time('proc-time');
const db = new PGlite('./pgdata')
let targetNum = 1;
for (let step = 0; step < 1000; step++) {
targetNum = step + 1;
let setValue = `k:${targetNum}`;
let sql = `INSERT INTO todo
(task, done) VALUES ('${setValue}', true);
`;
await db.exec(sql);
}
console.timeEnd('proc-time');
}catch(e){
console.error(e);
}
}
run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment