1.1.0 • Published 2 months ago

origindb-new v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

šŸ† 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

MethodDescription
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!