UNPKG

ryuudb

Version:

A lightweight, customizable JSON/YAML database for Node.js by Jr Busaco

100 lines (79 loc) 2.88 kB
# RyuuDB A lightweight, customizable database for Node.js, built by Jr Busaco (aka JrDev06). Think LowDB, but more flexible and just as easy to use. Supports JSON, YAML, custom storage, and more. ## Install ```bash npm install ryuudb ``` ## Quick Start ```javascript import RyuuDB from 'ryuudb'; // Basic JSON database const db = new RyuuDB(); // Add some data db.set('users', [{ id: 1, name: 'JrDev06' }, { id: 2, name: 'Alice' }]); // Get data console.log(db.get('users')); // [{ id: 1, name: 'JrDev06' }, { id: 2, name: 'Alice' }] // Find one console.log(db.find('users', { id: 1 })); // { id: 1, name: 'JrDev06' } // Filter with a function console.log(db.filter('users', user => user.name.startsWith('J'))); // [{ id: 1, name: 'JrDev06' }] // Update db.update('users', { id: 1 }, { name: 'Jr Busaco' }); // Remove db.remove('users', { id: 2 }); // Chain it up db.set('posts', []) .set('posts', [{ id: 1, title: 'Yo' }]) .update('posts', { id: 1 }, { title: 'Yo World' }); // Clear db.clear('posts'); // or db.clear() for everything ``` ## Customize It ```javascript // YAML file const yamlDb = new RyuuDB({ filePath: 'data.yaml', format: 'yaml' }); // In-memory for testing const memDb = new RyuuDB({ adapter: 'memory' }); // Custom storage class MyAdapter { async read() { return { users: [] }; } async write(data) { console.log('Saved:', data); } } const customDb = new RyuuDB({ adapter: new MyAdapter() }); // Listen for changes db.on('save', data => console.log('Saved:', data)); ``` ## Features - Dead-simple API, chainable methods. - JSON or YAML files, or roll your own storage. - Works with Node.js (14+), CommonJS, ES Modules, TypeScript. - Custom queries with functions for power users. - Events to hook into saves, updates, etc. - Lightweight, with `js-yaml` as the only optional dependency. ## API - `new RyuuDB(options)`: Start a new database. - `get(path?)`: Grab data at a path (or all data). - `set(path, value)`: Set data at a path. - `find(path, query | fn)`: Find first match (object or function). - `filter(path, query | fn)`: Get all matches (object or function). - `update(path, query | fn, updates)`: Update first match. - `remove(path, query | fn)`: Delete matches. - `clear(path?)`: Wipe a path or the whole thing. - `save()`: Force a save. - `load()`: Force a reload. - `on(event, fn)`: Listen for `load`, `save`, `set`, `update`, `remove`, `clear`. ## Options - `filePath`: Where to save (default: `db.json`). - `format`: `json` or `yaml` (default: `json`). - `adapter`: `file`, `memory`, or your own (default: `file`). - `debounce`: Save delay in ms (default: 100). - `defaultData`: Starting data (default: `{}`). ## Custom Adapters ```javascript class MyAdapter { async read() { /* return data */ } async write(data) { /* save data */ } } ``` ## License MIT, by Jr Busaco (https://www.facebook.com/jrr.busaco.2025).