tinycoll
Version:
A minimal reactive document store with Mongo-like querying, reactivity, TTL support, and optional persistence.
20 lines (19 loc) • 499 B
JavaScript
import { get, set, clear, createStore } from 'idb-keyval';
export class IndexedDbStorage {
#store;
constructor() {
this.#store = createStore('tinycoll', 'tinycoll');
}
async get(key) {
return get(key, this.#store);
}
async set(key, val) {
return set(key, val, this.#store);
}
static async clear() {
return clear(createStore('tinycoll', 'tinycoll'));
}
}
if (typeof window !== 'undefined') {
window['idb'] = IndexedDbStorage;
}