lumedb
v1.1.0
Published
Advanced JSON database with nested object support, backup system and multiple adapters
Maintainers
Readme
LumeDB
A lightweight, fast, and reliable JSON database for Node.js with nested object support and automatic backup system.
Features
- 🚀 Fast & Lightweight: In-memory caching with persistent storage
- 🔒 Safe & Reliable: Automatic backup system and data validation
- 🌳 Nested Objects: Support for deep object operations using dot notation
- ⚡ Sync & Async: Both synchronous and asynchronous API support
- 🛡️ Data Protection: Temporary file writing and validation before saving
- 🧹 Auto Cleanup: Optional removal of empty objects (noBlankData)
- 📖 Readable Format: Optional pretty-printing for stored data
- ⏰ Configurable Backups: Customizable backup interval
Installation
npm install lumedbQuick Start
const LumeDB = require('lumedb');
const db = new LumeDB();
// Synchronous Operations
db.set('user.name', 'John');
console.log(db.get('user.name')); // John
console.log(db.fetch('user')); // { name: 'John' }
db.delete('user.name');
// Asynchronous Operations
await db.setAsync('config.theme', 'dark');
const theme = await db.getAsync('config.theme');
await db.deleteAsync('config.theme');
// Array Operations
await db.push('users', { id: 1, name: 'Alice' });
await db.push('users', { id: 2, name: 'Bob' });
await db.unpush('users', { id: 1, name: 'Alice' });API Reference
Basic Operations
Synchronous
db.set(key, value): Set a valuedb.get(key): Get a valuedb.fetch(key): Alias for getdb.delete(key): Delete a valuedb.has(key): Check if key exists
Asynchronous
db.setAsync(key, value): Set a valuedb.getAsync(key): Get a valuedb.fetchAsync(key): Alias for getAsyncdb.deleteAsync(key): Delete a value
Array Operations
db.push(key, value): Add value to arraydb.unpush(key, value): Remove value from arraydb.delByPriority(key, priority): Delete item by indexdb.setByPriority(key, value, priority): Set item by index
Database Management
db.all(): Get all datadb.deleteAll(): Clear all datadb.setReadable(boolean): Toggle pretty-printingdb.noBlankData(boolean): Toggle auto-cleanupdb.setFolder(path): Set database folderdb.setFile(name): Set database filenamedb.setCheckUpdates(boolean): Toggle update checkingdb.setBackupInterval(minutes): Set backup interval in minutes
Configuration
const db = new LumeDB({
folder: './database', // Database folder
file: 'mydb', // Database filename
readable: true, // Pretty-print stored data
noBlankData: true, // Remove empty objects
checkUpdates: true, // Check for updates
backupInterval: 5 // Backup interval in minutes (default: 5)
});Data Safety Features
- Automatic Backups: Creates backup files at configurable intervals (default: 5 minutes)
- Safe Writing: Uses temporary files for atomic writes
- Data Validation: Validates data format before saving
- Backup Recovery: Automatically recovers from backup if main file is corrupted
Best Practices
Use dot notation for nested operations:
db.set('users.123.profile.name', 'John');Enable
noBlankDatato keep your database clean:db.noBlankData(true);Configure backup interval based on your needs:
db.setBackupInterval(15); // Backup every 15 minutes
License
This project is licensed under the MIT License - see the LICENSE file for details.
