Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Node.js with a SQLite database (based on sample from https://github.com/mapbox/node-sqlite3)
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('data/demodb01');
db.serialize(function() {
db.run("CREATE TABLE IF NOT EXISTS demo (runtime REAL)");
db.run("INSERT INTO demo (runtime) VALUES (?)", new Date().getTime());
db.each("SELECT runtime FROM demo", function(err, row) {
console.log("This app was run at " + row.runtime);
});
});
db.close();
@koalahamlet
Copy link

koalahamlet commented Aug 5, 2014

@dalelane I'm currently getting this error when I try and run the file.

events.js:72
throw er; // Unhandled 'error' event
^
Error: SQLITE_CANTOPEN: unable to open database file

@vandenoever
Copy link

vandenoever commented Oct 5, 2014

@ koalahamlet the database would be written to 'data/demodb01'. This fails if the directory 'data' does not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment