Skip to content

Commit 9c2d597

Browse files
committed
feat: add set methods
1 parent e31c869 commit 9c2d597

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,3 @@
3939
"@types/node": "^25.5.2"
4040
}
4141
}
42-

src/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import { DatabaseSync, DatabaseSyncOptions } from "node:sqlite"
22
export { version } from "../package.json"
33

4-
export class SqliteMap<K, V> {
4+
export class SqliteMap<K extends string, V> {
55
private db: DatabaseSync
66

77
constructor(path: string, options?: DatabaseSyncOptions) {
88
this.db = new DatabaseSync(path, options)
99
this.db.exec("CREATE TABLE IF NOT EXISTS map (key TEXT PRIMARY KEY, value TEXT)")
1010
}
11+
12+
set(key: K, data: V): this {
13+
const stmt = this.db.prepare(`INSERT OR REPLACE INTO cache (key, value) VALUES (?, ?)`)
14+
stmt.run(String(key), JSON.stringify(data), Date.now())
15+
return this
16+
}
1117
}

0 commit comments

Comments
 (0)