Commit 09b55954 by Konstantin Käfer

match code formatting

parent 6a666dd9
/* /**
Shows how to use chaining rather than the `serialize` method * Shows how to use chaining rather than the `serialize` method.
*/ */
(function () { "use strict";
"use strict";
require('long-stack-traces'); var sqlite3 = require('sqlite3').verbose();
var db;
var sqlite3 = require('sqlite3').verbose(), function createDb() {
db;
function createDb() {
console.log("createDb chain"); console.log("createDb chain");
db = new sqlite3.Database('chain.sqlite3', createTable); db = new sqlite3.Database('chain.sqlite3', createTable);
} }
function createTable() { function createTable() {
console.log("createTable lorem"); console.log("createTable lorem");
db.run("CREATE TABLE IF NOT EXISTS lorem (info TEXT)", insertRows); db.run("CREATE TABLE IF NOT EXISTS lorem (info TEXT)", insertRows);
} }
function insertRows() { function insertRows() {
console.log("insertRows Ipsum i"); console.log("insertRows Ipsum i");
var stmt = db.prepare("INSERT INTO lorem VALUES (?)"), var stmt = db.prepare("INSERT INTO lorem VALUES (?)");
i;
for (i = 0; i < 10; i++) { for (var i = 0; i < 10; i++) {
stmt.run("Ipsum " + i); stmt.run("Ipsum " + i);
} }
stmt.finalize(readAllRows); stmt.finalize(readAllRows);
} }
function readAllRows() { function readAllRows() {
console.log("readAllRows lorem"); console.log("readAllRows lorem");
db.all("SELECT rowid AS id, info FROM lorem", function(err, rows) { db.all("SELECT rowid AS id, info FROM lorem", function(err, rows) {
rows.forEach(function (row) { rows.forEach(function (row) {
console.log(row.id + ": " + row.info); console.log(row.id + ": " + row.info);
}); });
closeDb(); closeDb();
}); });
} }
function closeDb() { function closeDb() {
console.log("closeDb"); console.log("closeDb");
db.close(); db.close();
} }
function runChainExample() { function runChainExample() {
createDb(); createDb();
} }
runChainExample(); 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