I'm trying to use the sqlite3
module to create an in memory SQLite database and the adm-zip
module to save it into a zip file. So far I have been able to create an in memory database and add data to it, but I have been unsuccessful in finding a way to store it in a zip made through adm-zip
as it requires either a file, buffer or string.
My question is this: does the sqlite3
module even support storing or saving as a buffer? If it doesn't then what would be an advisable solution for storing temporary files in Node.js when the script is used as both a requirable module and a command line script?
I've included the code I've been using to test with below and a cloneable gist.
main.js
var fs = require('fs'),
admzip = require('adm-zip'),
sqlite3 = require('sqlite3').verbose(),
zip = new admzip(),
db = new sqlite3.Database('test.sqlite');
// db = new sqlite3.Database(':memory:');
db.serialize(function() {
db.run('CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY, name TEXT);');
db.run('INSERT OR IGNORE INTO test(name) VALUES ("neogeek");');
});
zip.addFile('README.md', '#SQLite3 + ADM-ZIP Test');
// zip.addFile('db.sqlite', db);
db.close();
fs.writeFileSync('test.zip', zip.toBuffer(), 'utf8');
package.json
{
"private": true,
"dependencies": {
"sqlite3": "3.0.2",
"adm-zip": "0.4.4"
}
}