-
-
Save padillla/6529104 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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 <[email protected]>" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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