forked from zycbob/node-webkit-sqlite3-windows-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (34 loc) · 927 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var http = require('http');
http.createServer(function(request, response) {
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('db');
db.serialize(function() {
/*db.run('CREATE TABLE lorem (info TEXT)');
var stmt = db.prepare('INSERT INTO lorem VALUES (?)');
for (var i = 0; i < 10; i++) {
stmt.run('Ipsum ' + i);
}
stmt.finalize();*/
var body = '';
db.each('SELECT rowid AS id, info FROM lorem',
function(err, row) {
console.log(row.id + ': ' + row.info);
body += row.id + ': ' + row.info + '<br />';
},
function(){
var html = '<html>'+
'<head>'+
'<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />'+
'</head>'+
'<body>'+
body+
'</body>'+
'</html>';
response.writeHead(200, {'Content-Type': 'text/html'});
response.write(html);
response.end();
}
);
});
db.close();
}).listen(8888);