abdulrahman.db
v1.1.0
Published
A simple JSON-based database package for managing key-value data and arrays, with support for delete and sorting operations.
Downloads
6
Readme
# abdulrahman.db
abdulrahman.db is a simple, lightweight, and easy-to-use package for local data storage using a JSON file. It allows you to store key-value pairs and arrays, retrieve data, add/remove data, and more, all from a JSON file stored locally.
## Features
- Store and retrieve key-value data
- Manage arrays (push, remove, find, clear, sort)
- Add and subtract numeric values
- Delete keys and data
- Clear the entire database
## Installation
To install the package, run:
npm install abdulrahman.db
## Usage
```javascript
const TaylerDB = require('abdulrahman.db');
const db = new TaylerDB('mydatabase.json');
// Set a key-value pair
db.set('name', 'Abdulrahman');
// Get the value of a key
console.log(db.get('name')); // 'Abdulrahman'
// Add a numeric value
db.add('age', 25);
console.log(db.get('age')); // 25
// Push items to an array
db.pushToArray('tasks', 'Task 1');
db.pushToArray('tasks', 'Task 2');
// Get the array
console.log(db.getArray('tasks')); // ['Task 1', 'Task 2']
// Remove an item from an array
db.removeFromArray('tasks', 'Task 1');
console.log(db.getArray('tasks')); // ['Task 2']
// Sort the array
db.sortArray('tasks', (a, b) => a.localeCompare(b));
console.log(db.getArray('tasks')); // ['Task 2', 'Task 1']
// Delete a key
db.delete('name');
console.log(db.get('name')); // null
// Clear all data in the database
db.clearDatabase();Functions
set(key, value): Set a value for a specific key.get(key): Retrieve the value associated with the key.delete(key): Delete a key and its associated value.has(key): Check if a key exists in the database.add(key, value): Add a numeric value.subtract(key, value): Subtract a numeric value.pushToArray(key, value): Add an item to an array.removeFromArray(key, value): Remove an item from an array.clearArray(key): Clear the contents of an array.getArray(key): Retrieve the array stored under the key.findInArray(key, condition): Find an item in an array that matches a condition.sortArray(key, compareFunction): Sort an array stored under the key.clearDatabase(): Clear all data in the database.keys(): Retrieve all keys.values(): Retrieve all values.size(): Get the number of stored items.updateInArray(key, condition, newValue): Update an item in an array.
Author:
abdulrahman.db is developed by Abdulrahman.
