cleanup
This commit is contained in:
parent
4e612cb224
commit
28d57323b6
6 changed files with 316 additions and 35 deletions
33
store/idb.js
Normal file
33
store/idb.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// lib/idb.js
|
||||
import { createStore, get, set, del, entries, clear } from 'idb-keyval'
|
||||
|
||||
// Named stores — each maps to a distinct IDBObjectStore
|
||||
export const itemsStore = createStore('app-db', 'items')
|
||||
export const userStore = createStore('app-db', 'user')
|
||||
export const cacheStore = createStore('app-db', 'cache')
|
||||
|
||||
// Typed wrappers — keeps raw idb-keyval calls out of the rest of the app
|
||||
// and gives you one place to add validation, logging, or migration logic
|
||||
|
||||
export const db = {
|
||||
items: {
|
||||
getAll: () => entries(itemsStore),
|
||||
get: (id) => get(id, itemsStore),
|
||||
set: (id, value) => set(id, value, itemsStore),
|
||||
remove: (id) => del(id, itemsStore),
|
||||
clear: () => clear(itemsStore),
|
||||
},
|
||||
|
||||
user: {
|
||||
get: () => get('user', userStore),
|
||||
set: (value) => set('user', value, userStore),
|
||||
clear: () => del('user', userStore),
|
||||
},
|
||||
|
||||
cache: {
|
||||
get: (key) => get(key, cacheStore),
|
||||
set: (key, value) => set(key, value, cacheStore),
|
||||
remove: (key) => del(key, cacheStore),
|
||||
clear: () => clear(cacheStore),
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue