-
-
Save rcstr/6551535 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 = { | |
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