0.0.8 • Published 5 years ago
@ndjson-utils/sqlite v0.0.8
@ndjson-utils/sqlite
Stream ndjson to and from a SQLite database
Install
npm install @ndjson-utils/sqliteto-sql
Arguments:
-t/--tablethe table name (required)-f/--filethe SQLite file (required)-pkcolumn that should be private key (optional, a column will be added if not defined)
Example usage
Suppose you have a ndjson stream such as data.js:
const generate = () => JSON.stringify({
num: Math.floor(Math.random() * 1000000),
str: Math.random() > 0.5 ? 'AAA' : 'BBB'
})
let n = 0
while (n < 1000) {
n = n + 1
console.log(generate())
}Insert it to a table test in db.sqlite with:
node data | to-sql -t test -f db.sqlitefrom-sql
Arguments:
-q/--querythe SQL query (required if-qf/--queryFileis not defined)-qf/--queryFilean.sqlfile with the query (required if-q/--queryis not defined)-f/--filethe SQLite file (required)-n/--ndjsonreturn as ndjson stream (optional, returns a json array by default)
Example usage
Extract the table created above to json:
from-sql -q "SELECT * FROM test" -f db.sqliteto an ndjson stream:
from-sql -q "SELECT * FROM test" -f db.sqlite -n trueOr have a query.sql file as:
SELECT * FROM testand run:
from-sql -qf query.sql -f db.sqlite -n true