Skip to content

Instantly share code, notes, and snippets.

@rcstr
Forked from padillla/SQLiteToJSON.js
Last active December 23, 2015 00:09
Show Gist options
  • Save rcstr/6551535 to your computer and use it in GitHub Desktop.
Save rcstr/6551535 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 = {
table :table.tbl_name,
row: row
};
fs.writeFile(outputFilename, JSON.stringify(tableRow), function(err) {
if(err) {
console.log(err);
} else {
console.log("JSON saved to " + outputFilename);
}
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment