MCPcopy Create free account
hub / github.com/TanStack/db / ElectronSQLiteStorageAdapter

Class ElectronSQLiteStorageAdapter

examples/electron/offline-first/src/db/todos.ts:37–73  ·  view source on GitHub ↗

* SQLite-backed storage adapter for the offline transactions outbox. * Stores pending mutations in the main process SQLite database via IPC, * so they survive app restarts (unlike IndexedDB in Electron).

Source from the content-addressed store, hash-verified

35 * so they survive app restarts (unlike IndexedDB in Electron).
36 */
37class ElectronSQLiteStorageAdapter implements StorageAdapter {
38 private prefix: string
39
40 constructor(prefix = 'offline-tx:') {
41 this.prefix = prefix
42 }
43
44 private prefixedKey(key: string): string {
45 return `${this.prefix}${key}`
46 }
47
48 async get(key: string): Promise<string | null> {
49 return window.electronAPI.kv.get(this.prefixedKey(key))
50 }
51
52 async set(key: string, value: string): Promise<void> {
53 await window.electronAPI.kv.set(this.prefixedKey(key), value)
54 }
55
56 async delete(key: string): Promise<void> {
57 await window.electronAPI.kv.delete(this.prefixedKey(key))
58 }
59
60 async keys(): Promise<Array<string>> {
61 const allKeys = await window.electronAPI.kv.keys()
62 return allKeys
63 .filter((k) => k.startsWith(this.prefix))
64 .map((k) => k.slice(this.prefix.length))
65 }
66
67 async clear(): Promise<void> {
68 const keys = await this.keys()
69 for (const key of keys) {
70 await window.electronAPI.kv.delete(this.prefixedKey(key))
71 }
72 }
73}
74
75/**
76 * Fetch with retry and exponential backoff.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected