1.1.0 • Published 7 months ago

aiko-mydb v1.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Downloads DownloadPerMonth

MyDB

MyDB is a Node.js module that supports JSON and YAML database formats, providing an easy-to-use API for data storage and management.

Features

  • Supports JSON and YAML database formats.
  • Key-value-based data operations.
  • Add, update, delete, and filter data easily.
  • Centralized error reporting system.
  • Extendable structure to support new database types.

Installation

  1. Clone or download this repository:

    git clone https://github.com/furkibuu/mydb.git
  2. Install the required dependencies:

npm install mydb
  1. Integrate the module into your project.

Usage

Basic Setup

const MyDB = require('./MyDB');

// Initialize MyDB
const db = new MyDB('yaml', './data/aiko-mydb.yaml');

// Add data
await db.add('user1', { name: 'Furkan', age: 18 });

// Get data
const user = await db.get('user1');
console.log(user); // { name: 'Furkan', age: 18 }

// Update data
await db.set('user1', { name: 'Sedef', age: 18 });

// List all data
const allData = await db.all();
console.log(allData);

// Delete data
await db.delete('user1');

Supported Operations

OperationDescription
addAdds a new key-value pair.
getRetrieves the value of a specified key.
fetchSame as get, added for flexibility.
setUpdates the value of a specified key.
deleteDeletes a specified key.
allRetrieves all stored data.
deleteAllDeletes all stored data.
pushAppends a value to a key that stores an array (automatically creates an array if none exists).
filterFilters data based on a callback condition.
searchSearches for a specific key-value match.
sortSorts the data by a specified key in ascending (asc) or descending (desc) order.

Switching Between YAML and JSON

You can choose the database format by passing the type parameter during initialization:

// Using JSON
const dbJSON = new MyDB('json', './data/mydb.json');

// Using YAML
const dbYAML = new MyDB('yaml', './data/mydb.yaml');

Error Handling

The module logs errors with detailed information and offers guidance for troubleshooting. If you need further support, you can join the provided Discord server:

[MyDB] Error during operation: get
Need help? Join our Discord: https://discord.gg/AYRDhFpRXE

Requirements

  • Node.js 14.x or higher.

  • Dependencies such as YAML and fs.

Development

  • To contribute to this project, follow these steps:
  1. Clone the repository.

  2. Add new database adapters by defining a new class in the dbAdapters object.

  3. Add new operations by implementing additional methods in the MyDB class.

License

  • This project is licensed under the MIT License. See the LICENSE file for more details.

Support

  • If you encounter any issues or have suggestions, please create a GitHub issue or join our Discord server.
1.1.0

7 months ago

1.0.0

7 months ago