createQueryPersister
stableCreate a persister for qortex-query
Create a persistence adapter that connects qortex-query to a qortex-db instance. Supports localStorage, sessionStorage, and IndexedDB via the provided DB driver.
Subpath Export
Import from 'qortex-db/query' to ensure better tree-shaking. The main 'qortex-db' package only exports the core DB driver.
Async Safe
The persister automatically waits for the initial async DB read to finish before allowing any writes, preventing race conditions.
Signature
import { createQueryPersister } from 'qortex-db/query';function createQueryPersister(db: DB,config?: QueryPersisterConfig): Persister
Parameters
db
DBRequiredA qortex-db instance created via createDB().
config
QueryPersisterConfigDefault: {}Optional configuration.
config.burstKey
stringDefault: '1'Cache-bust key. When changed, stale persisted data is discarded.
config.storageKey
stringDefault: 'qortex-query-cache'Key used inside the DB to store the snapshot.
config.debounceTime
numberDefault: 100Debounce delay (ms) before writing to DB.
Returns
Returns
PersisterAn object compatible with qortex-query's Persister interface.
Examples
Basic Usage
Connect qortex-query to an IndexedDB instance
import { createDB } from 'qortex-db';import { createQueryPersister } from 'qortex-db/query';import { setDefaultConfig } from 'qortex-query';const db = createDB({ name: 'myapp', driver: 'indexedDB' });setDefaultConfig({persister: createQueryPersister(db, { burstKey: 'v2' })});