SQLite3 nodejs binding. It's simple to use and supports the both asynchronous and synchronous manners.
apt install libsqlite3-dev
(or brew)
You may need to install cmake-js
and typescript
npm i -g cmake-js
npm i -g typescript
npm i simpledbc
See example/
const {Connection} = require('simpledbc');
let conn = new Connection(db)
let stmt = conn.createStatement()
let query = `CREATE TABLE ${table}(idx INTEGER PRIMARY KEY AUTOINCREMENT, passwd TEXT, date DATETIME);`
stmt.execute(query)
.then(res => {
console.log(res);
})
let stmt = conn.createStatement();
let password = Math.round(Math.random() * 1000);
let query = `INSERT INTO ${table} (passwd, date) VALUES(${password},datetime(\'now\',\'localtime\'));`;
stmt.execute(query)
.then(res => {
console.log(res);
})
let stmt = conn.createStatement();
let query =`SELECT idx, passwd, date FROM ${table}`;
stmt.execute(query)
.then(res => {
while(res.next()) {
console.log(res.data);
// console.log(res.obj);
}
})
let stmt = conn.createStatement();
let password = 'new password';
let query = `UPDATE ${table} set passwd=\'${password}\', date=datetime(\'now\',\'localtime\') WHERE idx=1;`;
stmt.execute(query)
.then(res => {
if(res) {
console.log(`successfully updated to ${password}`);
}
})
let id = 1;
let stmt = conn.createStatement();
let query = `DELETE FROM admin WHERE idx=${id};`;
stmt.execute(query)
.then(res => {
//
})
You can use it like this as well.
async function removeAsync(conn) {
let id = 2;
let stmt = conn.createStatement();
let query = `DELETE FROM admin WHERE idx=${id};`;
let res = await stmt.execute(query)
console.log(`removeAsync ${res}`);
}
cd native;
mkdir build; cd build
cmake .. && make