bun-sqlite-key-value
Advanced tools
Comparing version 1.9.7 to 1.10.1
@@ -43,3 +43,3 @@ import { Database } from "bun:sqlite"; | ||
private renameStatement; | ||
private touchStatement; | ||
private setTtlStatement; | ||
constructor(filename?: string, options?: Options); | ||
@@ -96,3 +96,3 @@ deleteExpired(): void; | ||
rename(oldKey: string, newKey: string): boolean; | ||
touch(key: string, ttlMs?: number): boolean; | ||
setTtl(key: string, ttlMs?: number): boolean; | ||
hSet<T = any>(key: string, field: string, value: T, ttlMs?: number): boolean; | ||
@@ -99,0 +99,0 @@ hGet<T = any>(key: string, field: string): T | undefined; |
@@ -31,3 +31,3 @@ // src/index.ts | ||
renameStatement; | ||
touchStatement; | ||
setTtlStatement; | ||
constructor(filename, options) { | ||
@@ -92,3 +92,3 @@ const { | ||
this.renameStatement = this.db.query("UPDATE items SET key = $newKey WHERE key = $oldKey"); | ||
this.touchStatement = this.db.query("UPDATE items SET expires = $expires WHERE key = $key"); | ||
this.setTtlStatement = this.db.query("UPDATE items SET expires = $expires WHERE key = $key"); | ||
this.deleteExpired(); | ||
@@ -388,3 +388,3 @@ } | ||
} | ||
touch(key, ttlMs) { | ||
setTtl(key, ttlMs) { | ||
let expires; | ||
@@ -395,3 +395,3 @@ ttlMs = ttlMs ?? this.ttlMs; | ||
} | ||
return this.touchStatement.run({ key, expires }).changes === 1; | ||
return this.setTtlStatement.run({ key, expires }).changes === 1; | ||
} | ||
@@ -398,0 +398,0 @@ hSet(key, field, value, ttlMs) { |
{ | ||
"name": "bun-sqlite-key-value", | ||
"version": "1.9.7", | ||
"version": "1.10.1", | ||
"author": { | ||
@@ -5,0 +5,0 @@ "name": "Gerold Penz", |
@@ -837,3 +837,3 @@ # Bun SQLite Key Value | ||
```typescript | ||
touch(key: string, ttlMs?: number): boolean | ||
setTtl(key: string, ttlMs?: number): boolean | ||
``` | ||
@@ -843,3 +843,2 @@ | ||
Returns `true` if the `key` exists. | ||
Inspired by: https://docs.keydb.dev/docs/commands/#touch | ||
@@ -868,6 +867,6 @@ ### key | ||
// Update TTL | ||
store.touch("my-key", 10000) // --> true | ||
store.setTtl("my-key", 10000) // --> true | ||
// Delete TTL | ||
store.touch("my-key", 0) // --> true | ||
store.setTtl("my-key", 0) // --> true | ||
``` | ||
@@ -874,0 +873,0 @@ |
@@ -61,3 +61,3 @@ import { Database, type Statement } from "bun:sqlite" | ||
private renameStatement: Statement | ||
private touchStatement: Statement | ||
private setTtlStatement: Statement | ||
@@ -154,3 +154,3 @@ | ||
this.renameStatement = this.db.query("UPDATE items SET key = $newKey WHERE key = $oldKey") | ||
this.touchStatement = this.db.query("UPDATE items SET expires = $expires WHERE key = $key") | ||
this.setTtlStatement = this.db.query("UPDATE items SET expires = $expires WHERE key = $key") | ||
@@ -615,3 +615,3 @@ // Delete expired items | ||
// Inspired by: https://docs.keydb.dev/docs/commands/#touch | ||
touch(key: string, ttlMs?: number): boolean { | ||
setTtl(key: string, ttlMs?: number): boolean { | ||
let expires: number | undefined | ||
@@ -622,3 +622,3 @@ ttlMs = ttlMs ?? this.ttlMs | ||
} | ||
return this.touchStatement.run({key, expires}).changes === 1 | ||
return this.setTtlStatement.run({key, expires}).changes === 1 | ||
} | ||
@@ -625,0 +625,0 @@ |
71383
1069