The goal of this library is to provide developers with a more direct way of interfacing with their stores with type-safety in mind. It keeps transaction handling implicit for simple operations, keeping the headache away for trivial tasks. Built entirely with Promises.
npm install agile-store@latestThe library provides the method createStores to activate all of your stores all at once.
Each store follows one schema that's defined via an interface. Note that only calling the constructor doesn't make the store ready to use yet.
import { Store } from "agile-store"; interface Item { name: string; price: number; onSale: boolean; } export const itemsStore = new Store<Item>({ name: "items", keyPath: "name", autoIncrement: false, indices: ["price"], });
createStores asynchronously creates the database and opens the provided stores. After that, you can use the methods provided in the stores you made earlier. You may want to perform any main rendering logic after createStores executes (usually through .then()).
import { createStores } from "agile-store"; import { itemsStore } from "./db"; createStores("test-db", 1, [itemsStore]);
itemsStore.add({
name: "Piano",
price: 10000,
onSale: true,
});const record = await itemsStore.getOne("name", "Piano");Note that there are multiple ways to query for records, including a filter method that uses a user-provided qualifier function to return all records that pass the function.
itemsStore.put({
name: "Piano",
price: 10000,
onSale: false,
});Note that put requires a full object of the store's type. Partial object update operations coming soon.
itemsStore.deleteOne("Piano");