miniqdb
v1.0.0
Published
A lightweight, file-based, MongoDB-like database for Node.js with advanced querying, schema validation, soft deletes, and basic transactions.
Maintainers
Readme
MiniQDB
MiniQDB is a lightweight, file-based database for Node.js. It provides advanced querying, schema validation, soft deletes, and basic transaction support, all stored in a simple JSON file. MiniQDB is ideal for small projects, prototyping, or local apps that need persistent structured data without the overhead of a full database server.
Features
- File-based storage: All data is stored in a single JSON file.
- Collections: Organize your data into named collections.
- Schema validation: Enforce data structure and types.
- Advanced querying: Filter with logical and comparison operators.
- Soft deletes: Mark records as deleted without removing them.
- Transactions: Begin, commit, and rollback changes.
- Indexing: Create and use indexes for faster lookups.
- Bulk operations: Insert, update, and delete multiple records at once.
- Projection: Select specific fields to return in queries.
- Pagination, sorting, and aggregation: Built-in utilities for common data operations.
Installation
npm install miniqdbUsage
const { MiniQDB } = require('./src/miniqdb');
// Define a schema (optional)
const userSchema = {
name: { type: 'string', required: true, minLength: 2 },
age: { type: 'number', required: true },
email: { type: 'string', required: true }
};
// Create or open a collection
const users = new MiniQDB('users', userSchema);
// Insert a document
const user = users.insertOne({ name: 'Alice', age: 30, email: '[email protected]' });
// Find documents
const results = users.find({ age: { $gte: 18 } }, { name: 1, email: 1 });
// Update a document
users.updateOne({ name: 'Alice' }, { age: 31 });
// Soft delete a document
users.deleteById(user.id);
// Restore a soft-deleted document
users.restoreById(user.id);
// Transactions
users.beginTransaction();
try {
users.insertOne({ name: 'Bob', age: 25, email: '[email protected]' });
users.commit();
} catch (e) {
users.rollback();
}