npm.io
1.1.0 • Published 1 year ago

origindb-new

Licence
MIT
Version
1.1.0
Deps
4
Size
10 kB
Vulns
0
Weekly
0

OriginDB Updated

Blazing fast and flexible JSON database for Node.js.

Node.js 18+ MongoDB 4+ MIT License


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!

Keywords