yosie
v2.0.1
Published
A lightweight IndexedDB wrapper with TTL and hash-based operations.
Maintainers
Readme
IndexedDB TTL Store
A lightweight wrapper for IndexedDB that provides a Redis-like key-value API with TTL (time-to-live) support.
Features
- Key-value storage with expiration (TTL)
- Redis-like commands:
get,set,del,keys,ttl,getAll,delAll - Hash-like methods:
hget,hset,hdel - Automatic object store creation if missing
- TypeScript support (
index.d.tsincluded)
Installation
npm install yosieUsage
import { connectDB } from "yosie";
async function demo() {
// Connect to a database
const db = await connectDB("mydb");
// Connect to a store (auto-creates if missing)
const store = await db.connectStore("mystore");
// Set with TTL of 10 seconds
await store.set("foo", "bar", { ttl: 10 });
// Get value
const val = await store.get("foo"); // "bar"
// TTL check
const ttl = await store.ttl("foo"); // e.g., 8 (seconds left)
// Delete key
await store.del("foo");
}API
connectDB(dbName: string): Promise<Database>
Connect (or create) an IndexedDB database.
Database.connectStore(storeName: string): Promise<Store>
Connect to (or create) an object store.
Store Methods
get(key)→ value orundefinedset(key, value, { ttl?, expiresAt? })→ voidttl: seconds (≤ 0 means immediate expiration)expiresAt: absolute ms timestamp (takes precedence overttl)
del(key)→ voidgetAll()→ all non-expired valueskeys()→ all keys of non-expired valuesdelAll()→ voidhget(key, field)→ field value from stored objecthset(key, field, value)→ set field in objecthdel(key, field)→ delete field in objectttl(key)→ number-2: key does not exist-1: key exists but has no expiration0: key expired> 0: seconds remaining
License
MIT
