@aux4/db-sqlite
v0.0.2
Published
Database CLI for SQLite
Downloads
4
Readme
@aux4/db-sqlite
JavaScript
Install
$ npm install @aux4/db-sqlite
Execute Query
const Database = require("@aux4/db-sqlite");
const db = new Database({
database: "test.db"
});
(async () => {
await db.open();
const { data } = await db.execute("select * from table where id = :id", { id: 1 });
console.log(JSON.stringify(data, null, 2));
await db.close();
})();
Query Stream
const Database = require("@aux4/db-sqlite");
const db = new Database({
database: "test.db"
});
const stream = await db.stream("select * from table where id = :id", { id: 1 });
stream.on("data", row => {
console.log(JSON.stringify(row, null, 2));
});
stream.on("error", err => {
console.error(err.message);
});
stream.on("close", async () => {
await db.close();
});
Command Line
Install
$ npm install --global @aux4/db
$ npm install --global @aux4/db-sqlite
Usage
Execute Query
$ db execute --database test.db --query "select * from table where id = :id" --id 1
Stream Query
$ db stream --database test.db --query "select * from table where id = :id" --id 1
Using @aux4/config
$ npm install --global @aux4/config
create config.yaml
config:
dev:
sqlite:
database: test.db
$ db execute --configFile config.yaml --config dev/sqlite --query "select * from table where id = :id" --id 1