Skip to content

Commit

Permalink
0.0.5 - add nw test
Browse files Browse the repository at this point in the history
  • Loading branch information
Fritz committed Oct 20, 2016
1 parent d0d3e9b commit 1ffdc23
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
```sh
npm install unix-sqlcipher

# for NW.js (formally node-webkit)
npm i unix-sqlcipher --runtime=node-webkit --target=0.12.3 --target_arch=x64
```

```js
Expand All @@ -15,16 +18,17 @@ db.serialize(function() {
db.run("PRAGMA KEY = 'secret'");
db.run("PRAGMA CIPHER = 'aes-128-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.run("Ipsum " + i);
}
stmt.finalize();

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

Expand Down
29 changes: 29 additions & 0 deletions nw/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<script>
require('nw.gui').Window.get().focus()

// https://github.com/delaballe/node-sqlcipher#usage
// https://coolaj86.com/articles/building-sqlcipher-for-node-js-on-raspberry-pi-2/
'use strict';
var sqlite3 = require('../').verbose();
var db = new sqlite3.Database('../test.db');

db.serialize(function() {
db.run("PRAGMA KEY = 'secret'");
db.run("PRAGMA CIPHER = 'aes-128-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>
4 changes: 4 additions & 0 deletions nw/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "nwtest",
"main": "main.html"
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unix-sqlcipher",
"version": "0.0.4",
"version": "0.0.5",
"description": "Encrypted sqlite3 for MacOS and Linux",
"keywords": [
"sqlite3",
Expand All @@ -10,6 +10,8 @@
],
"repository": "git://github.com/fritx/unix-sqlcipher.git",
"scripts": {
"test": "node test",
"nwtest": "nw nw",
"nwbuild": "npm i --runtime=node-webkit --target=0.12.3 --target_arch=x64",
"preinstall": "node preinstall",
"postinstall": "node postinstall"
Expand Down
5 changes: 3 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ db.serialize(function() {
db.run("PRAGMA KEY = 'secret'");
db.run("PRAGMA CIPHER = 'aes-128-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.run("Ipsum " + i);
}
stmt.finalize();

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

Expand Down

0 comments on commit 1ffdc23

Please sign in to comment.