Skip to content

Node module for converting Sqlite3 tables to JSON

License

Notifications You must be signed in to change notification settings

falcon-client/sqlite-json-export

This branch is 16 commits ahead of, 19 commits behind fitnr/sqlite-json:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

de32ff1 · Jul 29, 2018

History

42 Commits
Jun 11, 2017
Jun 11, 2017
Jun 11, 2017
Jun 11, 2017
Nov 1, 2015
Apr 20, 2015
Jul 29, 2018
Jun 11, 2017
Jun 11, 2017
Jun 11, 2017
Jul 29, 2018
Jul 29, 2018

Repository files navigation

sqlite-json-export

Convert Sqlite3 tables to JSON

Build Status NPM version Dependency Status npm

Install

npm install --save sqlite-json-export

Todo:

  • Migrate to a Promise based API
  • Extract all tables

API

constructor(database)

Create an instance of sqlite-json.

Example:

const SqliteJsonExport = require('sqlite-json-export');
let exporter = new SqliteJsonExport('example.db');

database

The path to an SQLite database or a sqlite3 client instance.

Type: sqlite3.Database or string

Example:

const SqliteJsonExport = require('sqlite-json-export');
const sqlite3 = require('sqlite3');
const db = new sqlite3.Database('./mydb.sqlite3');
const exporter = new SqliteJsonExport('example.db');

json(sql, options, callback)

Export JSON from a specified table, and use it in the given callback.

Example:

exporter.json('select * FROM myTable', (err, json) => {
  // handle error or do something with the JSON
  // "[{"foo": 1}, {"foo": 2}, {"foo": 3}]"
});

options.columns

An optional list of columns to output.

Type: Array

Example:

exporter.json({table: 'myTable' columns: ['foo']}, (err, json) => {
  // "[{"foo": 1}, {"foo": 2}, {"foo": 3}]"
});

options.key

An optional column name.

By default, the result is an JSON array of objects. If key is given, a JSON object is returned, each row keyed to the given column value.

Type: string

Example:

exporter.json('myTable', {key: 'foo'}, (err, json) => {
  // "{"1": {"foo": 1}, "2": {"foo": 2}, "3": {"foo": 3}}"
});

options.table

A table to address with the columns, and where options.

Type: string

options.where

A where clause to add to the query.

Type: string

Example:

exporter.json({table: 'myTable', where: 'foo > 1'}, (err, json) => {
  // "[{"foo": 2}, {"foo": 3}]"
});

tables(cb)

List all tables in the current database.

Example:

exporter.tables((err, tables) => {
  // tables === ['foo', 'bar', 'baz']
});

save(table, filename, cb)

Save the contents of a table to the specified output file.

Example:

exporter.save('table_name', 'data/table_name.json', (err, data) => {
    // Optionally do something else with the JSON.
});

About

Node module for converting Sqlite3 tables to JSON

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%