indexed-rds
v0.0.1
Published
browser-kv is a simplified web-indexedDB method
Downloads
4
Readme
browser-kv
browser-kv is a simplified web-indexedDB method
Feature
- gzip 0.3kb, just a utility method
- Nicely abstracts the set / get / remove methods
- Automatically parses/formats objects
- Supports autoIncrement
- Supports Typescript
- Fully Promise-based CRUD operations
- Compatible with environments lacking indexedDB, uses localStorage for storage
- Compatible with environments lacking uint8Array
Use
import { NanoIndexed } from "nano-indexed";
// Example of explicitly declared instance
const example = async () => {
const db = NanoIndexed("my-db", {
// keyPath?: string; // Custom object content as the primary key
// autoIncrement?: boolean; // Whether the primary key auto-increments
});
// Store data
await db.set("page", { name: "bobo", age: 20 });
// Retrieve data
const data = await db.get("page");
// Update partial values
const nextData = await db.update("page", { name: "dog" });
// Delete data
await db.remove("page");
};
example();
// Auto-increment type example
const autoIncrementExample = async () => {
const db = NanoIndexed("my-db",{
autoIncrement: boolean; // Auto-increment primary key
});
// Store data
await db.set(null, { name: "bobo", age: 20 });
// Retrieve data, using an int id
const data = await db.get(1);
// Update partial values
const nextData = await db.update(1, { name: "dog" });
// Delete data
await db.remove(1);
};
autoIncrementExample();