var fs = require("fs");
var file = "./test.db";
var exists = fs.existsSync(file);

if(!exists) {
  console.log("Creating DB file.");
  fs.openSync(file, "w");
}

var sqlite3 = require("sqlite3").verbose();
var db = new sqlite3.Database(file);

db.serialize(function() {
  if(!exists) {
    db.run("CREATE TABLE Stuff (thing TEXT)");
  
    var stmt = db.prepare("INSERT INTO Stuff VALUES (?)");

    //Insert random data
    var rnd;
    for (var i = 0; i < 10; i++) {
      rnd = Math.floor(Math.random() * 10000000);
      stmt.run("Thing #" + rnd);
    }
    stmt.finalize();
  }

  db.each("SELECT rowid AS id, thing FROM Stuff", function(err, row) {
    console.log(row.id + ": " + row.thing);
  });
});

db.close();

@@ -15,17 +15,16 @@
 re(%22fs%22)
-;
 %0Avar fil
@@ -38,17 +38,16 @@
 test.db%22
-;
 %0Avar exi
@@ -71,17 +71,16 @@
 nc(file)
-;
 %0A%0Aif(!ex
@@ -121,17 +121,16 @@
  file.%22)
-;
 %0A  fs.op
@@ -146,17 +146,16 @@
 le, %22w%22)
-;
 %0A%7D%0A%0Avar 
@@ -192,17 +192,16 @@
 erbose()
-;
 %0Avar db 
@@ -228,19 +228,47 @@
 se(file)
-;
 %0A%0A
+var startup = function() %7B%0A  
 db.seria
@@ -287,16 +287,18 @@
 n() %7B%0A  
+  
 if(!exis
@@ -299,24 +299,26 @@
 (!exists) %7B%0A
+  
     db.run(%22
@@ -334,33 +334,73 @@
 BLE 
-Stuff (thing TEXT)%22);
+user (id INTEGER PRIMARY KEY AUTOINCREMENT, email CHAR(50))%22)%0A
 %0A  
-%0A
     
@@ -438,191 +438,66 @@
 NTO 
-Stuff VALUES (?)%22);%0A%0A    //Insert random data%0A    var rnd;%0A    for (var i = 0; i %3C 10; i++) %7B%0A      rnd = Math.floor(Math.random() * 10000000);%0A      stmt.run(%22Thing #%22 + rnd);
+user (email) VALUES ('jtms@aol.com')%22)%0A      stmt.run()
 %0A  
-  %7D%0A
     
@@ -515,15 +515,18 @@
 ze()
-;
 %0A
+  
   %7D%0A%0A
+  
   db
@@ -543,37 +543,33 @@
 ECT 
-rowid AS id, thing FROM Stuff
+u.id, u.email FROM user u
 %22, f
@@ -584,24 +584,26 @@
 err, row) %7B%0A
+  
     console.
@@ -630,27 +630,30 @@
 row.
-thing);%0A
+email)%0A 
   
+ 
 %7D)
-;
 %0A
+  
 %7D)
-;
 %0A%0A
+  
 db.c
@@ -662,6 +662,17 @@
 se()
-;
+%0A%7D%0Astartup()
 %0A

create user table