Dexie Plugin
The Dexie Plugin stores data in IndexedDB via Dexie. Ideal for web apps needing persistent, performant client-side storage.
Installation
npm install @routier/dexie-plugin dexie
Basic Usage
import { DataStore } from "@routier/datastore";
import { s } from "@routier/core/schema";
import { DexiePlugin } from "@routier/dexie-plugin";
const userSchema = s
.define("users", {
id: s.string().key().identity(),
email: s.string().distinct(),
name: s.string(),
createdAt: s.date().default(() => new Date()),
})
.compile();
class Ctx extends DataStore {
users = this.collection(userSchema).create();
constructor() {
super(new DexiePlugin("app"));
}
}
const ctx = new Ctx();
await ctx.users.addAsync({ name: "Ada", email: "[email protected]" });
await ctx.saveChangesAsync();Notes
- Runs in browsers (and Electron) using IndexedDB.
- Use for persistent storage with good performance and large capacity.