一覧へ戻る
remvze-org/zevadb(新しいタブで開きます)
主要言語: TypeScript
📦 A typesafe JSON file database with Zod schema validation.
- star 数
- 19
- watcher 数
- 0
- fork 数
- 0
- issue 数
- 0
- 最終更新
- 2026/05/05
主要言語: TypeScript
📦 A typesafe JSON file database with Zod schema validation.
A type-safe JSON file database with Zod schema validation.
db.data and db.set()npm install zevadb zod
Note: ZevaDB requires Zod v4 as a peer dependency.
import { z } from "zod"; import { ZevaDB } from "zevadb"; const UserSchema = z.object({ id: z.string(), name: z.string(), }); const PostSchema = z.object({ id: z.string(), title: z.string(), content: z.string(), authorId: z.string(), }); const db = new ZevaDB({ path: "./db.json", schemas: { users: z.array(UserSchema), posts: z.array(PostSchema), }, initial: { users: [], posts: [], }, }); await db.read(); db.data.users.push({ id: "1", name: "Alice" }); db.set("users", [{ id: "2", name: "Bob" }]); await db.write();
Add migrations before read():
db.addMigration("Add createdAt to posts", (prevData) => { return { ...prevData, posts: prevData.posts.map((post) => ({ ...post, createdAt: new Date().toISOString(), })), }; }); await db.read(); // pending migrations are applied and persisted
If the database file is malformed or schema-invalid, ZevaDB moves it to a backup file and reinitializes from initial:
<db-path>.backup-<timestamp>
ZevaDB uses a lock file (<db-path>.lock) to serialize file operations across processes and reduces write corruption risk with atomic writes. In a multi-writer setup, last successful write still wins.