1.1.0 ⢠Published 2 months ago
origindb-new v1.1.0
š OriginDB Updated
⨠Features
ā
Simple and lightweight JSON-based database.
ā
Supports file storage and MongoDB adapters.
ā
Chainable methods for easy manipulation.
ā
Fully compatible with Node.js 18+.
š¦ Installation
Make sure you have Node.js 18+ installed, then run:
npm install origindb-new
š Usage
š Using File Storage (JSON-based)
const OriginDB = require('origindb-new');
const db = new OriginDB('files', './data'); // Stores data in "./data"
const money = db.money('wallets');
// š¹ Add a wallet
money.set('john_doe', { balance: 100, currency: 'USD' });
// š¹ Get wallet data
console.log(money.get('john_doe')); // { balance: 100, currency: 'USD' }
// š¹ Check if a wallet exists
console.log(money.has('john_doe')); // true
// š¹ Get all wallet keys
console.log(money.keys()); // ['john_doe']
// š¹ Get all wallet values
console.log(money.values()); // [{ balance: 100, currency: 'USD' }]
// š¹ Update wallet balance
money.update('john_doe', (data) => ({ ...data, balance: data.balance + 50 }));
// š¹ Delete a wallet
money.unset('john_doe');
// š¹ Check the full wallets object
console.log(money.object()); // {}
āļø Using MongoDB
Ensure you have a MongoDB instance running, then use:
const OriginDB = require('origindb-new');
const db = new OriginDB('mongo', 'mongodb://localhost:27017/mydatabase'); // Connects to MongoDB
const money = db.money('wallets');
// š¹ Add a wallet
money.set('jane_doe', { balance: 250, currency: 'EUR' });
// š¹ Get wallet data
console.log(money.get('jane_doe')); // { balance: 250, currency: 'EUR' }
// š¹ Check if a wallet exists
console.log(money.has('jane_doe')); // true
// š¹ Get all wallet keys
console.log(money.keys()); // ['jane_doe']
// š¹ Get all wallet values
console.log(money.values()); // [{ balance: 250, currency: 'EUR' }]
// š¹ Update wallet balance
money.update('jane_doe', (data) => ({ ...data, balance: data.balance - 50 }));
// š¹ Delete a wallet
money.unset('jane_doe');
// š¹ Check the full wallets object
console.log(money.object()); // {}
š API Reference
Method | Description |
---|---|
db.money(name) | Creates or retrieves a money storage table (previously db.table ). |
money.set(key, value) | Stores a value under the specified key. |
money.get(key) | Retrieves the value stored under the key. |
money.has(key) | Checks if a key exists in the table. |
money.keys() | Returns all keys in the table. |
money.values() | Returns all values in the table. |
money.update(key, callback) | Modifies an existing entry using a callback function. |
money.unset(key) | Deletes an entry from the table. |
money.object() | Returns the entire table object. |
š Requirements
ā
Node.js 18+
ā
MongoDB 4+ (only if using MongoDB adapter)
š License
This project is licensed under the MIT License.
šØāš» Contributors
Originally developed by Phil (CreaturePhil)
Updated for Node.js 18+ and MongoDB 5+ compatibility.
ā Support
If you like this project, please consider starring ā the repository!