npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aiko-mydb

v1.1.0

Published

A flexible database wrapper supporting JSON and YAML formats.

Downloads

148

Readme

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

| Operation | Description | |-------------|-----------------------------------------------------------------------------| | add | Adds a new key-value pair. | | get | Retrieves the value of a specified key. | | fetch | Same as get, added for flexibility. | | set | Updates the value of a specified key. | | delete | Deletes a specified key. | | all | Retrieves all stored data. | | deleteAll | Deletes all stored data. | | push | Appends a value to a key that stores an array (automatically creates an array if none exists). | | filter | Filters data based on a callback condition. | | search | Searches for a specific key-value match. | | sort | Sorts 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.