adonix-db
v1.0.9
Published
A simple file-based JSON database with schema validation and relationships for Node.js.
Maintainers
Readme
🚀 AdonixDB
A Minimalist, File-Based Database Engine for Node.js
Lightweight. Predictable. Typed. — AdonixDB brings Prisma-style APIs to a local JSON-file system.
⚙️ Overview
AdonixDB is a schema-validated JSON database designed for Node.js environments where simplicity and control matter most. It provides:
- 🧩 Schema enforcement with default values
- 🔗 Relations (One-to-Many & Many-to-One)
- 🧠 Prisma-inspired query API
- 💾 Zero-setup persistence via local JSON files
📦 Installation
npm install adonix-db🗂 Directory Layout
Once connected, AdonixDB creates a folder named adonix_db_files/ at your project root.
Each model maps to a single JSON file (user.json, product.json, etc.), ensuring clear separation of concerns.
📁 adonix_db_files
┣ 📄 user.json
┗ 📄 product.json🧠 Quick Start
1️⃣ Connect & Initialize
import { AdonixDB } from 'adonix-db';
const db = new AdonixDB();
await db.connect(); // Initializes folder + loads schema
console.log('✅ Connected to AdonixDB');2️⃣ Define Models (Schema + Relations)
Each model includes:
- Automatic fields:
id,createdAt,updatedAt - Declarative schema:
type,required,default - Optional relationship map
const UserSchema = {
email: { type: 'string', required: true },
username: { type: 'string', default: 'anonymous' },
age: { type: 'number', default: 18 },
};
db.defineModel('user', UserSchema);Relationships are defined at model registration:
const ProductSchema = {
name: { type: 'string', required: true },
price: { type: 'number', required: true },
userId: { type: 'string', required: true }, // FK
};
db.defineModel('user', UserSchema, {
products: { model: 'product', type: 'One-to-Many', foreignKey: 'userId' },
});
db.defineModel('product', ProductSchema, {
owner: { model: 'user', type: 'Many-to-One', foreignKey: 'userId' },
});🔍 Querying & CRUD API
All models are accessible via db.<modelName>.
Each exposes a predictable async API:
| Method | Purpose |
| :-------------- | :-------------------------------------------- |
| .create() | Insert one record (supports nested writes) |
| .findUnique() | Find one record by unique criteria |
| .findMany() | Query multiple records (filter/sort/paginate) |
| .update() | Update record by ID |
| .delete() | Delete record by ID |
➕ Create (with Nested Write)
const newUser = await db.user.create({
data: {
email: '[email protected]',
username: 'tester',
products: {
create: [
{ name: 'Monitor', price: 300 },
{ name: 'Keyboard', price: 50 },
],
},
},
});🔗 Include Relations (Join)
// Many → One
const product = await db.product.findUnique({
where: { name: 'Monitor' },
include: { owner: true },
});
// One → Many
const user = await db.user.findUnique({
where: { id: newUser.id },
include: { products: true },
});🔍 Advanced Filtering
const results = await db.product.findMany({
where: {
price: { gte: 50, lte: 300 },
name: { contains: 'board' },
},
orderBy: { price: 'asc' },
skip: 0,
take: 10,
});Supported Operators
| Operator | Description |
| :----------------------- | :---------------------------- |
| eq, neq | Equal / Not equal |
| gt, gte, lt, lte | Numeric comparisons |
| in, notin | Array membership |
| contains | Substring match (string only) |
✏️ Update & Delete
await db.user.update({
where: { id: newUser.id },
data: { age: 25, email: '[email protected]' },
});
await db.user.delete({
where: { id: newUser.id },
});🧩 Why AdonixDB?
| Feature | Description | | :-------------- | :------------------------------------- | | 🪶 Lightweight | Zero dependencies, no external server | | 🧱 Schema-safe | Validates every write | | 🔄 JSON-based | Human-readable, git-friendly storage | | 💡 Familiar API | Inspired by Prisma & Mongoose patterns |
🧭 Best Practices (Senior-Level Tips)
- Keep models small & cohesive: treat each JSON file as a domain boundary.
- Never mutate raw JSON manually. Use provided API to preserve indexes and timestamps.
- Validate business logic in code, not the schema — AdonixDB ensures structure, not semantics.
- For large data (>10k records), prefer
.findMany()withskip/takepagination.
🧰 Example Project Structure
📦 my-project
┣ 📁 adonix_db_files
┣ 📄 index.js
┗ 📄 package.json🧾 License
MIT © 2025 — Designed for developers who love clarity and control.
