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

nqr.db

v0.1.0-beta

Published

A database package for managing key-value pairs in JSON format.

Downloads

10

Readme

NQRDB

NQRDB is a simple and versatile JSON-based database class for Node.js. It allows for CRUD operations, querying, and various utility functions on a JSON file used as a database.

Installation

To use NQRDB, you need to have Node.js installed. Install the package using npm:

npm install nqrdb

Usage

Here's a quick overview of how to use NQRDB:

Initialization

import NQRDB from 'nqrdb';

// Create an instance of the database, with an optional file name.
const db = new NQRDB('mydatabase.json');

Basic Operations

  • Set a value:

    db.set('key', 'value');
  • Fetch a value:

    const value = db.fetch('key');
  • Update a value:

    db.update('key', 'newValue');
  • Delete a key:

    db.delete('key');
  • Check if a key exists:

    const exists = db.has('key');

Advanced Operations

  • Increment a numeric value:

    db.add('numericKey', 10);
  • Decrement a numeric value:

    db.subtract('numericKey', 5);
  • Perform mathematical operations:

    db.math('numericKey', '+', 10); // Adds 10
    db.math('numericKey', '-', 5);  // Subtracts 5
  • Filter entries:

    const results = db.filter((key, value) => value > 10);
  • Map entries:

    const mapped = db.map((key, value) => value * 2);
  • Clone the database:

    db.clone('newDatabase');
  • Merge databases:

    db.mergeAll('otherDatabase1.json', 'otherDatabase2.json');
  • Backup the database:

    db.backup('backup');

Error Handling

NQRDB uses custom error handling with the NQRError class and various error codes. Refer to the ERROR_CODES enum for details on error types.

API

Methods

  • size - Returns the number of keys in the database.
  • keys() - Returns an array of all keys.
  • values() - Returns an array of all values.
  • filter(callback) - Filters entries based on a callback.
  • map(callback) - Maps entries based on a callback.
  • find(callback) - Finds an entry based on a callback.
  • some(callback) - Checks if any entry matches a callback.
  • every(callback) - Checks if all entries match a callback.
  • countBy(callback) - Counts entries matching a callback.
  • updater(key, updater) - Updates a value using a callback function.
  • update(key, value) - Updates a value directly.
  • removeByValue(value) - Removes entries matching a value.
  • clone(newKey, [keyToClone]) - Clones data to a new key.
  • rename(oldKey, newKey) - Renames a key.
  • toggle(key) - Toggles a boolean value.
  • mergeAll(...filePaths) - Merges multiple databases.
  • pluck(key) - Extracts values by a key.
  • set(key, value) - Sets a value.
  • fetch(key) - Fetches a value.
  • has(key) - Checks if a key exists.
  • delete(key) - Deletes a key.
  • fetchAll() - Retrieves all data.
  • backup(fileName) - Backs up the database.
  • add(key, value) - Increments a numeric value.
  • subtract(key, value) - Decrements a numeric value.
  • reset() - Clears all data.
  • all(limit) - Retrieves all entries with an optional limit.
  • push(key, value) - Appends a value to an array.
  • math(key, operation, value) - Performs a mathematical operation.
  • merge(key, data) - Merges data with an existing key.
  • clear(key) - Clears an array or object.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Feel free to open issues or submit pull requests if you want to contribute to NQRDB.