Skip to content

Instantly share code, notes, and snippets.

@dalelane
Created June 15, 2014 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dalelane/d0259abd7a39cfb15cbe to your computer and use it in GitHub Desktop.
Save dalelane/d0259abd7a39cfb15cbe to your computer and use it in GitHub Desktop.
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();
@vandenoever
Copy link

@ 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