PouchDB Plugin
Client-side database with optional CouchDB sync. Great for offline-first apps.
Installation
npm install @routier/pouchdb-plugin pouchdb
Basic Usage
import { DataStore } from "@routier/datastore";
import { s } from "@routier/core/schema";
import { PouchDbPlugin } from "@routier/pouchdb-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 PouchDbPlugin("myapp"));
}
}
const ctx = new Ctx();
await ctx.users.addAsync({ name: "Ada", email: "[email protected]" });
await ctx.saveChangesAsync();Notes
- Pair with CouchDB for two-way sync.
- See Syncing guide for setup.
- When storing multiple entity types in one database, scope each collection to a discriminator. See: Scope a collection (single physical store).