Node.js sqlite3 nodejs binding
npm install simpledbcSQLite3 nodejs binding. It's simple to use and supports the both asynchronous and synchronous manners.
!Node.js CI


bash
apt install libsqlite3-dev(or brew)
`You may need to install
cmake-js and typescript
`
npm i -g cmake-js
npm i -g typescript
`
Install
`bash
npm i simpledbc
`Example
See example/$3
`js
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);
})
`$3
`js
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);
})
`$3
`js
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);
}
})
`$3
`js
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});
}
})
`$3
`js
let id = 1;
let stmt = conn.createStatement();
let query = DELETE FROM admin WHERE idx=${id};;
stmt.execute(query)
.then(res => {
//
})
`$3
You can use it like this as well.
`js
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});
}
`
(Optional) Native only build
`bash
cd native;
mkdir build; cd build
cmake .. && make
``