rzcore-db
v1.0.0
Published
Lightweight, adapter-based JSON/Memory database for RZCore.
Maintainers
Readme
rzcore-db
Lightweight, adapter-based database library for the RZCore ecosystem. Supports generic adapters, with built-in support for JSON (file-based) and Memory storage.
Installation
npm install rzcore-dbQuick Start
const { RZCoreDB, JsonAdapter } = require('rzcore-db');
// Initialize with JSON Adapter
const db = new RZCoreDB({
adapter: new JsonAdapter({ path: './data' })
});
(async () => {
await db.connect();
const users = db.collection('users');
// Insert
await users.insert({ name: 'Alice', role: 'admin' });
// Find
const admins = await users.find({ role: 'admin' });
console.log(admins);
// Update
await users.update({ name: 'Alice' }, { role: 'super-admin' });
// Delete
await users.delete({ role: 'super-admin' });
})();Features
- Adapter Pattern: Easily switch between Memory (for tests) and JSON (for production).
- MongoDB-like API: Familiar
find,insert,update,deletesyntax. - Lightweight: Zero dependencies by default.
API Reference
new RZCoreDB(config)
config.adapter: Instance of an adapter (e.g.,new JsonAdapter()).
Collection Methods
find(query, options): Returns array of documents.findOne(query): Returns single document or null.findById(id): Returns document by ID.insert(data): Inserts a document. Returns the document with generated ID.update(query, data): Updates multiple documents. Returns modified count.updateById(id, data): Updates single document by ID.delete(query): Deletes multiple documents. Returns deleted count.deleteById(id): Deletes single document.count(query): Returns count of matching documents.
