Created
June 15, 2014 20:55
-
-
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)
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('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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ koalahamlet the database would be written to 'data/demodb01'. This fails if the directory 'data' does not exist.