@bibliotek/sqlite 0.0.3 → 0.0.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bibliotek/sqlite",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Sqlite3 database using async/await",
5
5
  "type": "module",
6
6
  "exports": "./sqlite.js",
package/sqlite.js CHANGED
@@ -148,4 +148,7 @@ export class Statement {
148
148
  });
149
149
  });
150
150
  }
151
+
152
+ get lastID() { return this.stmt.lastID; }
153
+ get changes() { return this.stmt.changes; }
151
154
  }
@@ -59,7 +59,7 @@ describe("Database", () => {
59
59
 
60
60
  it("should resolve with .lastID", async () => {
61
61
  const db = Database.memory();
62
- await db.run("create table t (id int, key text)");
62
+ await db.run("create table t (id integer not null primary key autoincrement, key text)");
63
63
  await db.run("insert into t values (null, 'foo')");
64
64
  const result = await db.run("insert into t values (null, 'bar')");
65
65
 
@@ -138,13 +138,14 @@ describe("Database", () => {
138
138
  });
139
139
 
140
140
  describe("Statement", () => {
141
- let sqlite, insert, select;
141
+ let sqlite, insert, select, update;
142
142
 
143
143
  beforeEach(async () => {
144
144
  sqlite = Database.memory();
145
- await sqlite.run("create table t (id int, key text)");
145
+ await sqlite.run("create table t (id integer not null primary key autoincrement, key text)");
146
146
  insert = sqlite.prepare("insert into t values (?, ?)");
147
147
  select = sqlite.prepare("select key from t where id between ? and ? order by id");
148
+ update = sqlite.prepare("update t set key = 'none' where id > ?");
148
149
  });
149
150
 
150
151
  describe(".run(...params)", () => {
@@ -155,6 +156,22 @@ describe("Statement", () => {
155
156
  const row = await sqlite.get("select count(*) c from t");
156
157
  expect(row.c).to.be(2);
157
158
  });
159
+
160
+ it("should set .lastID on statement", async () => {
161
+ await insert.run(null, "foo");
162
+ await insert.run(null, "bar");
163
+
164
+ expect(insert.lastID).to.be(2);
165
+ });
166
+
167
+ it("should set .changes on statement", async () => {
168
+ await insert.run(null, "foo");
169
+ await insert.run(null, "bar");
170
+ await insert.run(null, "baz");
171
+ await update.run(0);
172
+
173
+ expect(update.changes).to.be(3);
174
+ });
158
175
  });
159
176
 
160
177
  describe(".each(...params)", () => {