Skip to content

Instantly share code, notes, and snippets.

@mannharleen
Created November 8, 2020 10:55
Show Gist options
  • Save mannharleen/dca49ff4ec79d813138682ee28be5e56 to your computer and use it in GitHub Desktop.
Save mannharleen/dca49ff4ec79d813138682ee28be5e56 to your computer and use it in GitHub Desktop.
playing around with node-sqlite
const sqlite3 = require("sqlite3");
const { open } = require("sqlite");
(async () => {
// open the database
const db = await open({
filename: '/tmp/db',
driver: sqlite3.cached.Database //sqlite3.Database
})
const db1 = await open({
filename: '/tmp/db',
driver: sqlite3.cached.Database // sqlite3.Database
})
await db.exec("create table t1 (col1)");
await db.exec("insert into t1 values ('a')");
let tx1 = await db.exec(`
BEGIN;
insert into t1 values ('c');
create temp table t2 (col1 int);
-- insert into t1 values ('d');
insert into t1 values ('b');
insert into t2 values ('t2a');
COMMIT;
`);
console.log(await db.all("select * from t1"));
console.log(await db1.all("select * from t2"));
})().catch(e => {
console.error('error occured', e)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment