Skip to content

Instantly share code, notes, and snippets.

@padillla
Forked from diestrin/SQLiteToJSON.js
Last active December 22, 2015 20:49
Show Gist options
  • Save padillla/6529104 to your computer and use it in GitHub Desktop.
Save padillla/6529104 to your computer and use it in GitHub Desktop.
{
"name": "SQLiteToJSON",
"version": "0.0.0",
"description": "Convert a SQLite db to json objects",
"main": "app.js",
"dependencies": {},
"devDependencies": {
"sqlite3": "~2.1.16"
},
"author": "Diego Barahona <diestrin@gmail.com>"
}
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('./db.db');
var fs = require('fs');
var outputFilename = './output.json';
var jsonOutput = db.serialize(function() {
db.each("SELECT * FROM sqlite_master WHERE type='table'", function(err, table) {
db.each("SELECT * FROM " + table.tbl_name, function(err, row) {
var tableRow;
tableRow = {
table: table.tbl_name,
row: row
};
fs.appendFile(outputFilename, JSON.stringify(tableRow), function(err) {
if (err) {
console.log(err);
} else {
console.log("Written to JSON " + tableRow.table + " on " outputFilename);
}
//console.log(tableRow);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment