@bibliotek/sqlite 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/sqlite.js +7 -2
- package/test/test-sqlite.js +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bibliotek/sqlite",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Sqlite3 database using async/await",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./sqlite.js",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@bibliotek/synch": "^0.0.1",
|
|
12
|
-
"sqlite3": "^
|
|
12
|
+
"sqlite3": "^4.2.0"
|
|
13
13
|
},
|
|
14
14
|
"devDependencies": {
|
|
15
15
|
"expect.js": "^0.3.1",
|
package/sqlite.js
CHANGED
|
@@ -77,8 +77,13 @@ export class Database {
|
|
|
77
77
|
|
|
78
78
|
async run(sql) {
|
|
79
79
|
return new Promise((resolve, reject) => {
|
|
80
|
-
this.db.run(sql, err
|
|
81
|
-
if (err)
|
|
80
|
+
this.db.run(sql, function(err) {
|
|
81
|
+
if (err) {
|
|
82
|
+
reject(err);
|
|
83
|
+
} else {
|
|
84
|
+
const {lastID, changes} = this || {};
|
|
85
|
+
resolve({lastID, changes});
|
|
86
|
+
}
|
|
82
87
|
});
|
|
83
88
|
});
|
|
84
89
|
}
|
package/test/test-sqlite.js
CHANGED
|
@@ -56,6 +56,27 @@ describe("Database", () => {
|
|
|
56
56
|
expect(db.run.calledOnce).to.be(true);
|
|
57
57
|
expect(db.run.calledWith(sql)).to.be(true);
|
|
58
58
|
});
|
|
59
|
+
|
|
60
|
+
it("should resolve with .lastID", async () => {
|
|
61
|
+
const db = Database.memory();
|
|
62
|
+
await db.run("create table t (id int, key text)");
|
|
63
|
+
await db.run("insert into t values (null, 'foo')");
|
|
64
|
+
const result = await db.run("insert into t values (null, 'bar')");
|
|
65
|
+
|
|
66
|
+
expect(result).to.be.an("object");
|
|
67
|
+
expect(result.lastID).to.be(2);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should resolve with .changes", async () => {
|
|
71
|
+
const db = Database.memory();
|
|
72
|
+
await db.run("create table t (id int, key text)");
|
|
73
|
+
await db.run("insert into t values (1, 'foo')");
|
|
74
|
+
await db.run("insert into t values (3, 'bar')");
|
|
75
|
+
const result = await db.run("update t set key = 'new'");
|
|
76
|
+
|
|
77
|
+
expect(result).to.be.an("object");
|
|
78
|
+
expect(result.changes).to.be(2);
|
|
79
|
+
});
|
|
59
80
|
});
|
|
60
81
|
|
|
61
82
|
describe(".each(sql)", () => {
|