0.0.8 • Published 3 years ago

@ndjson-utils/sqlite v0.0.8

Weekly downloads
-
License
GPLv2
Repository
github
Last release
3 years ago

@ndjson-utils/sqlite

Stream ndjson to and from a SQLite database

Install

npm install @ndjson-utils/sqlite

to-sql

Arguments:

  • -t/--table the table name (required)
  • -f/--file the SQLite file (required)
  • -pk column 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.sqlite

from-sql

Arguments:

  • -q/--query the SQL query (required if -qf/--queryFile is not defined)
  • -qf/--queryFile an .sql file with the query (required if -q/--query is not defined)
  • -f/--file the SQLite file (required)
  • -n/--ndjson return 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.sqlite

to an ndjson stream:

from-sql -q "SELECT * FROM test" -f db.sqlite -n true

Or have a query.sql file as:

SELECT * FROM test

and run:

from-sql -qf query.sql -f db.sqlite -n true
0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago