Local Storage Plugin

Browser localStorage-backed plugin for simple persistence. Best for small datasets and quick prototypes.

Installation

npm install @routier/browser-storage-plugin

Basic Usage

import { DataStore } from "@routier/datastore";
import { s } from "@routier/core/schema";
import { LocalStoragePlugin } from "@routier/browser-storage-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 LocalStoragePlugin("app"));
    }
}

const ctx = new Ctx();
await ctx.users.addAsync({ name: "Ada", email: "[email protected]" });
await ctx.saveChangesAsync();

Notes

  • Synchronous API; storage limits (typically ~5–10MB).
  • Consider Dexie or PouchDB for larger datasets.