Loading sqlite/kv.test.ts +7 −7 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ test("SqliteKvStore.get()", async () => { const now = Temporal.Now.instant().epochMilliseconds; db.prepare(` INSERT INTO ${tableName} (key, value, expires_at) INSERT INTO ${tableName} (key, value, expires) VALUES (?, ?, ?) `).run( JSON.stringify(["foo", "bar", "ttl"]), Loading Loading @@ -81,7 +81,7 @@ test("SqliteKvStore.set()", async () => { assert.strictEqual(result.length, 1); assert.deepStrictEqual(JSON.parse(result[0].key), ["foo", "baz"]); assert.strictEqual(JSON.parse(result[0].value), "baz"); assert.strictEqual(result[0].expires_at, null); assert.strictEqual(result[0].expires, null); await store.set(["foo", "qux"], "qux", { ttl: Temporal.Duration.from({ days: 1 }), Loading @@ -93,7 +93,7 @@ test("SqliteKvStore.set()", async () => { assert.strictEqual(result2.length, 1); assert.deepStrictEqual(JSON.parse(result2[0].key), ["foo", "qux"]); assert.strictEqual(JSON.parse(result2[0].value), "qux"); assert(result2[0].expires_at >= result2[0].created + 86400000); assert(result2[0].expires >= result2[0].created + 86400000); await store.set(["foo", "quux"], true); const result3 = db.prepare(` Loading @@ -103,7 +103,7 @@ test("SqliteKvStore.set()", async () => { assert.strictEqual(result3.length, 1); assert.deepStrictEqual(JSON.parse(result3[0].key), ["foo", "quux"]); assert.strictEqual(JSON.parse(result3[0].value), true); assert.strictEqual(result3[0].expires_at, null); assert.strictEqual(result3[0].expires, null); } finally { await store.drop(); await db.close(); Loading Loading @@ -251,14 +251,14 @@ test("SqliteKvStore.set() - preserves created timestamp on update", async () => try { await store.set(["timestamp-test"], "initial"); const initialResult = db.prepare(` SELECT created, expires_at FROM ${tableName} SELECT created, expires FROM ${tableName} WHERE key = ? `).get(JSON.stringify(["timestamp-test"])); const initialCreated = (initialResult as { created: number }).created; assert(initialCreated > 0, "Initial created timestamp should be set"); assert.strictEqual( (initialResult as { expires_at: number | null }).expires_at, (initialResult as { expires: number | null }).expires, null, ); Loading @@ -268,7 +268,7 @@ test("SqliteKvStore.set() - preserves created timestamp on update", async () => await store.set(["timestamp-test"], "updated", { ttl }); const updatedResult = db.prepare(` SELECT created, expires_at FROM ${tableName} SELECT created, expires FROM ${tableName} WHERE key = ? `).get(JSON.stringify(["timestamp-test"])); Loading sqlite/kv.ts +9 −9 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ export class SqliteKvStore implements KvStore { .prepare(` SELECT value FROM "${this.#tableName}" WHERE key = ? AND (expires_at IS NULL OR expires_at > ?) WHERE key = ? AND (expires IS NULL OR expires > ?) `) .get(encodedKey, now); Loading Loading @@ -103,11 +103,11 @@ export class SqliteKvStore implements KvStore { this.#db .prepare( `INSERT INTO "${this.#tableName}" (key, value, created, expires_at) `INSERT INTO "${this.#tableName}" (key, value, created, expires) VALUES (?, ?, ?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value, expires_at = excluded.expires_at`, expires = excluded.expires`, ) .run(encodedKey, encodedValue, now, expiresAt); Loading Loading @@ -155,7 +155,7 @@ export class SqliteKvStore implements KvStore { .prepare(` SELECT value FROM "${this.#tableName}" WHERE key = ? AND (expires_at IS NULL OR expires_at > ?) WHERE key = ? AND (expires IS NULL OR expires > ?) `) .get(encodedKey, now) as { value: string } | undefined; const currentValue = currentResult === undefined Loading @@ -171,14 +171,14 @@ export class SqliteKvStore implements KvStore { this.#db .prepare(` UPDATE "${this.#tableName}" SET value = ?, expires_at = ? SET value = ?, expires = ? WHERE key = ? `) .run(newValueJson, expiresAt, encodedKey); } else if (newValue !== undefined) { this.#db .prepare(` INSERT INTO "${this.#tableName}" (key, value, created, expires_at) INSERT INTO "${this.#tableName}" (key, value, created, expires) VALUES (?, ?, ?, ?) `) .run(encodedKey, newValueJson, now, expiresAt); Loading Loading @@ -217,13 +217,13 @@ export class SqliteKvStore implements KvStore { key TEXT PRIMARY KEY, value TEXT NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, expires_at INTEGER expires INTEGER ) `); this.db.exec(` CREATE INDEX IF NOT EXISTS "idx_${this.#tableName}_expires" ON "${this.#tableName}" (expires_at) ON "${this.#tableName}" (expires) `); this.#initialized = true; Loading @@ -237,7 +237,7 @@ export class SqliteKvStore implements KvStore { this.#db .prepare(` DELETE FROM "${this.#tableName}" WHERE expires_at IS NOT NULL AND expires_at <= ? WHERE expires IS NOT NULL AND expires <= ? `) .run(now); } Loading Loading
sqlite/kv.test.ts +7 −7 Original line number Diff line number Diff line Loading @@ -53,7 +53,7 @@ test("SqliteKvStore.get()", async () => { const now = Temporal.Now.instant().epochMilliseconds; db.prepare(` INSERT INTO ${tableName} (key, value, expires_at) INSERT INTO ${tableName} (key, value, expires) VALUES (?, ?, ?) `).run( JSON.stringify(["foo", "bar", "ttl"]), Loading Loading @@ -81,7 +81,7 @@ test("SqliteKvStore.set()", async () => { assert.strictEqual(result.length, 1); assert.deepStrictEqual(JSON.parse(result[0].key), ["foo", "baz"]); assert.strictEqual(JSON.parse(result[0].value), "baz"); assert.strictEqual(result[0].expires_at, null); assert.strictEqual(result[0].expires, null); await store.set(["foo", "qux"], "qux", { ttl: Temporal.Duration.from({ days: 1 }), Loading @@ -93,7 +93,7 @@ test("SqliteKvStore.set()", async () => { assert.strictEqual(result2.length, 1); assert.deepStrictEqual(JSON.parse(result2[0].key), ["foo", "qux"]); assert.strictEqual(JSON.parse(result2[0].value), "qux"); assert(result2[0].expires_at >= result2[0].created + 86400000); assert(result2[0].expires >= result2[0].created + 86400000); await store.set(["foo", "quux"], true); const result3 = db.prepare(` Loading @@ -103,7 +103,7 @@ test("SqliteKvStore.set()", async () => { assert.strictEqual(result3.length, 1); assert.deepStrictEqual(JSON.parse(result3[0].key), ["foo", "quux"]); assert.strictEqual(JSON.parse(result3[0].value), true); assert.strictEqual(result3[0].expires_at, null); assert.strictEqual(result3[0].expires, null); } finally { await store.drop(); await db.close(); Loading Loading @@ -251,14 +251,14 @@ test("SqliteKvStore.set() - preserves created timestamp on update", async () => try { await store.set(["timestamp-test"], "initial"); const initialResult = db.prepare(` SELECT created, expires_at FROM ${tableName} SELECT created, expires FROM ${tableName} WHERE key = ? `).get(JSON.stringify(["timestamp-test"])); const initialCreated = (initialResult as { created: number }).created; assert(initialCreated > 0, "Initial created timestamp should be set"); assert.strictEqual( (initialResult as { expires_at: number | null }).expires_at, (initialResult as { expires: number | null }).expires, null, ); Loading @@ -268,7 +268,7 @@ test("SqliteKvStore.set() - preserves created timestamp on update", async () => await store.set(["timestamp-test"], "updated", { ttl }); const updatedResult = db.prepare(` SELECT created, expires_at FROM ${tableName} SELECT created, expires FROM ${tableName} WHERE key = ? `).get(JSON.stringify(["timestamp-test"])); Loading
sqlite/kv.ts +9 −9 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ export class SqliteKvStore implements KvStore { .prepare(` SELECT value FROM "${this.#tableName}" WHERE key = ? AND (expires_at IS NULL OR expires_at > ?) WHERE key = ? AND (expires IS NULL OR expires > ?) `) .get(encodedKey, now); Loading Loading @@ -103,11 +103,11 @@ export class SqliteKvStore implements KvStore { this.#db .prepare( `INSERT INTO "${this.#tableName}" (key, value, created, expires_at) `INSERT INTO "${this.#tableName}" (key, value, created, expires) VALUES (?, ?, ?, ?) ON CONFLICT(key) DO UPDATE SET value = excluded.value, expires_at = excluded.expires_at`, expires = excluded.expires`, ) .run(encodedKey, encodedValue, now, expiresAt); Loading Loading @@ -155,7 +155,7 @@ export class SqliteKvStore implements KvStore { .prepare(` SELECT value FROM "${this.#tableName}" WHERE key = ? AND (expires_at IS NULL OR expires_at > ?) WHERE key = ? AND (expires IS NULL OR expires > ?) `) .get(encodedKey, now) as { value: string } | undefined; const currentValue = currentResult === undefined Loading @@ -171,14 +171,14 @@ export class SqliteKvStore implements KvStore { this.#db .prepare(` UPDATE "${this.#tableName}" SET value = ?, expires_at = ? SET value = ?, expires = ? WHERE key = ? `) .run(newValueJson, expiresAt, encodedKey); } else if (newValue !== undefined) { this.#db .prepare(` INSERT INTO "${this.#tableName}" (key, value, created, expires_at) INSERT INTO "${this.#tableName}" (key, value, created, expires) VALUES (?, ?, ?, ?) `) .run(encodedKey, newValueJson, now, expiresAt); Loading Loading @@ -217,13 +217,13 @@ export class SqliteKvStore implements KvStore { key TEXT PRIMARY KEY, value TEXT NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, expires_at INTEGER expires INTEGER ) `); this.db.exec(` CREATE INDEX IF NOT EXISTS "idx_${this.#tableName}_expires" ON "${this.#tableName}" (expires_at) ON "${this.#tableName}" (expires) `); this.#initialized = true; Loading @@ -237,7 +237,7 @@ export class SqliteKvStore implements KvStore { this.#db .prepare(` DELETE FROM "${this.#tableName}" WHERE expires_at IS NOT NULL AND expires_at <= ? WHERE expires IS NOT NULL AND expires <= ? `) .run(now); } Loading