Created
November 8, 2020 10:55
-
-
Save mannharleen/dca49ff4ec79d813138682ee28be5e56 to your computer and use it in GitHub Desktop.
playing around with node-sqlite
This file contains hidden or 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
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