A simple, TypeScript-first JSON file database for local development and prototyping
✅ Good for:
❌ Not for:
No database server to install or configure. Just create a JSON file and start building. Perfect for getting started quickly without infrastructure overhead.
Built with TypeScript generics for full type safety. Get autocomplete, type checking, and catch errors at compile time instead of runtime.
It's just JSON! Open the file in any text editor to see exactly what's stored. No need for database clients or query tools to inspect your data.
Minimal dependencies keep your bundle small. Atomic file writes prevent data corruption if your app crashes during a write operation.
// types.tsimport{ Resource }from'octavedb';export interfaceUserextendsResource{ username:string; email:string; }export interfacePostextendsResource{ title:string; content:string; userId:User['id']; }export interfaceDatabase{ users:User[]; posts:Post[];}
// database.json{"users": [],"posts": [] }
// lib/db.tsimport{ createClient }from'octavedb';import type{ Database }from'./types';export constdb = createClient<Database>('./database.json');// Also export the helpers for convenienceexport{ makeResource, makeDateTime, makeId }from'octavedb';
import{ db, makeResource, makeDateTime }from'./lib/db';import type{ User }from'./types';// CREATEfunctioncreateUser(username:string, email:string) {constuser = makeResource<User>({ username, email });constdata = db.read(); data.users.push(user); db.write(data);returnuser; }// READfunctiongetUser(id:string) {constdata = db.read();returndata.users.find(u => u.id === id); }// UPDATEfunctionupdateUser(id:string, email:string) {constdata = db.read();constindex = data.users.findIndex(u => u.id === id);if(index <0)throw newError('User not found'); data.users[index] = { ...data.users[index], email, updatedAt: makeDateTime() }; db.write(data);returndata.users[index]; }// DELETEfunctiondeleteUser(id:string) {constdata = db.read();constindex = data.users.findIndex(u => u.id === id);if(index <0)throw newError('User not found');constdeleted = data.users.splice(index,1)[0]; db.write(data);returndeleted; }
Creates a database client for the specified JSON file.
const db = createClient<Database>('./database.json');Reads and returns the entire database.
const data = db.read();Writes data to the database file atomically.
db.write(data);Creates a new resource with automatic id, createdAt, and updatedAt fields.
const user = makeResource<User>({ username: 'johndoe' });Helper functions for generating UUIDs and ISO timestamps.