-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.html
32 lines (26 loc) · 901 Bytes
/
main.html
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
<script>
// https://github.com/delaballe/node-sqlcipher#usage
// https://coolaj86.com/articles/building-sqlcipher-for-node-js-on-raspberry-pi-2/
// https://www.zetetic.net/sqlcipher/sqlcipher-api
'use strict';
var sqlite3 = require('cross-sqlcipher').verbose();
// in electron, it should be `__dirname`
// instead of `process.cwd()`
var dbFile = __dirname + '/test.db';
var db = new sqlite3.Database(dbFile);
db.serialize(function() {
db.run("PRAGMA KEY = 'secret'");
db.run("PRAGMA CIPHER = 'aes-256-cbc'");
db.run("DROP TABLE IF EXISTS lorem");
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();
db.each("SELECT rowid AS id, info FROM lorem", function(err, row) {
document.write(row.id + ": " + row.info + '<br>');
});
});
db.close();
</script>