Loading sqlite/kv.test.ts +19 −11 Original line number Diff line number Diff line Loading @@ -45,20 +45,21 @@ test("SqliteKvStore.get()", async () => { const { db, tableName, store } = getStore(); try { await store.initialize(); const now = Temporal.Now.instant().epochMilliseconds; db.prepare(` INSERT INTO ${tableName} (key, value) VALUES (?, ?) `).run(JSON.stringify(["foo", "bar"]), JSON.stringify(["foobar"])); INSERT INTO ${tableName} (key, value, created) VALUES (?, ?, ?) `).run(JSON.stringify(["foo", "bar"]), JSON.stringify(["foobar"]), now); assert.deepStrictEqual(await store.get(["foo", "bar"]), ["foobar"]); const now = Temporal.Now.instant().epochMilliseconds; db.prepare(` INSERT INTO ${tableName} (key, value, expires) VALUES (?, ?, ?) INSERT INTO ${tableName} (key, value, expires, created) VALUES (?, ?, ?, ?) `).run( JSON.stringify(["foo", "bar", "ttl"]), JSON.stringify(["foobar"]), now + 500, Temporal.Now.instant().epochMilliseconds, ); await delay(500); assert.strictEqual(await store.get(["foo", "bar", "ttl"]), undefined); Loading Loading @@ -138,9 +139,13 @@ test("SqliteKvStore.delete()", async () => { assert.strictEqual(result.length, 0); db.prepare(` INSERT INTO ${tableName} (key, value) VALUES (?, ?) `).run(JSON.stringify(["foo", "qux"]), JSON.stringify(["qux"])); INSERT INTO ${tableName} (key, value, created) VALUES (?, ?, ?) `).run( JSON.stringify(["foo", "qux"]), JSON.stringify(["qux"]), Temporal.Now.instant().epochMilliseconds, ); await store.delete(["foo", "qux"]); const result2 = db.prepare(` SELECT * FROM ${tableName} Loading Loading @@ -258,7 +263,10 @@ test("SqliteKvStore.set() - preserves created timestamp on update", async () => `).get(JSON.stringify(["timestamp-test"])); const initialCreated = (initialResult as { created: number }).created; assert(initialCreated > 0, "Initial created timestamp should be set"); assert( initialCreated !== undefined, "Initial created timestamp should be set", ); assert.strictEqual( (initialResult as { expires: number | null }).expires, null, Loading @@ -275,7 +283,7 @@ test("SqliteKvStore.set() - preserves created timestamp on update", async () => `).get(JSON.stringify(["timestamp-test"])); assert.strictEqual( (updatedResult as { created: number }).created, (updatedResult as { created: string }).created, initialCreated, "Created timestamp should remain unchanged after update", ); Loading sqlite/kv.ts +12 −12 Original line number Diff line number Diff line Loading @@ -225,7 +225,7 @@ export class SqliteKvStore implements KvStore { CREATE TABLE IF NOT EXISTS "${this.#tableName}" ( key TEXT PRIMARY KEY, value TEXT NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created INTEGER NOT NULL, expires INTEGER ) `); Loading Loading
sqlite/kv.test.ts +19 −11 Original line number Diff line number Diff line Loading @@ -45,20 +45,21 @@ test("SqliteKvStore.get()", async () => { const { db, tableName, store } = getStore(); try { await store.initialize(); const now = Temporal.Now.instant().epochMilliseconds; db.prepare(` INSERT INTO ${tableName} (key, value) VALUES (?, ?) `).run(JSON.stringify(["foo", "bar"]), JSON.stringify(["foobar"])); INSERT INTO ${tableName} (key, value, created) VALUES (?, ?, ?) `).run(JSON.stringify(["foo", "bar"]), JSON.stringify(["foobar"]), now); assert.deepStrictEqual(await store.get(["foo", "bar"]), ["foobar"]); const now = Temporal.Now.instant().epochMilliseconds; db.prepare(` INSERT INTO ${tableName} (key, value, expires) VALUES (?, ?, ?) INSERT INTO ${tableName} (key, value, expires, created) VALUES (?, ?, ?, ?) `).run( JSON.stringify(["foo", "bar", "ttl"]), JSON.stringify(["foobar"]), now + 500, Temporal.Now.instant().epochMilliseconds, ); await delay(500); assert.strictEqual(await store.get(["foo", "bar", "ttl"]), undefined); Loading Loading @@ -138,9 +139,13 @@ test("SqliteKvStore.delete()", async () => { assert.strictEqual(result.length, 0); db.prepare(` INSERT INTO ${tableName} (key, value) VALUES (?, ?) `).run(JSON.stringify(["foo", "qux"]), JSON.stringify(["qux"])); INSERT INTO ${tableName} (key, value, created) VALUES (?, ?, ?) `).run( JSON.stringify(["foo", "qux"]), JSON.stringify(["qux"]), Temporal.Now.instant().epochMilliseconds, ); await store.delete(["foo", "qux"]); const result2 = db.prepare(` SELECT * FROM ${tableName} Loading Loading @@ -258,7 +263,10 @@ test("SqliteKvStore.set() - preserves created timestamp on update", async () => `).get(JSON.stringify(["timestamp-test"])); const initialCreated = (initialResult as { created: number }).created; assert(initialCreated > 0, "Initial created timestamp should be set"); assert( initialCreated !== undefined, "Initial created timestamp should be set", ); assert.strictEqual( (initialResult as { expires: number | null }).expires, null, Loading @@ -275,7 +283,7 @@ test("SqliteKvStore.set() - preserves created timestamp on update", async () => `).get(JSON.stringify(["timestamp-test"])); assert.strictEqual( (updatedResult as { created: number }).created, (updatedResult as { created: string }).created, initialCreated, "Created timestamp should remain unchanged after update", ); Loading
sqlite/kv.ts +12 −12 Original line number Diff line number Diff line Loading @@ -225,7 +225,7 @@ export class SqliteKvStore implements KvStore { CREATE TABLE IF NOT EXISTS "${this.#tableName}" ( key TEXT PRIMARY KEY, value TEXT NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created INTEGER NOT NULL, expires INTEGER ) `); Loading