@blaze-chat/effect-idb
v0.0.6
Published
IndexedDB API Wrapped with Effect-TS
Downloads
247
Maintainers
Readme
effect-idb
IndexedDB API Wrapped with Effect-TS.
For sake of a smaller bundle size, this library uses Micro and recommends using valibot or zod/mini.
Currently not supported
IDBObjectStoreParameters.autoIncrementIDBIndex.multiEntry- Some
IDBObjectStoreAPIs likecount() IDBCursorIDBKeyRange
Example
import { Micro, pipe } from "effect";
import * as v from "valibot";
import { Database } from "./database";
import { defineObjectStoreSchema } from "./object-store";
const userSchema = v.object({
id: v.string(),
name: v.string(),
age: v.number(),
});
const db = await Micro.runPromise(
Database.open("", 1, {
user: defineObjectStoreSchema({
schema: userSchema,
key: "id",
}),
}),
);
const result = await Micro.runPromise(
db.useTransaction("user", "readonly", (tx) =>
pipe(
tx.objectStore("user"),
Micro.flatMap((x) => x.get("0")),
),
),
);
console.log(result);