Commit 6a666dd9 by Konstantin Käfer

Merge branch 'master' of https://github.com/coolaj86/node-sqlite3 into coolaj86-master

parents 0bd387be fae3d0fd
/*
Shows how to use chaining rather than the `serialize` method
*/
(function () {
"use strict";
require('long-stack-traces');
var sqlite3 = require('sqlite3').verbose(),
db;
function createDb() {
console.log("createDb chain");
db = new sqlite3.Database('chain.sqlite3', createTable);
}
function createTable() {
console.log("createTable lorem");
db.run("CREATE TABLE IF NOT EXISTS lorem (info TEXT)", insertRows);
}
function insertRows() {
console.log("insertRows Ipsum i");
var stmt = db.prepare("INSERT INTO lorem VALUES (?)"),
i;
for (i = 0; i < 10; i++) {
stmt.run("Ipsum " + i);
}
stmt.finalize(readAllRows);
}
function readAllRows() {
console.log("readAllRows lorem");
db.all("SELECT rowid AS id, info FROM lorem", function(err, rows) {
rows.forEach(function (row) {
console.log(row.id + ": " + row.info);
});
closeDb();
});
}
function closeDb() {
console.log("closeDb");
db.close();
}
function runChainExample() {
createDb();
}
runChainExample();
}());
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment