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

@ajayos/nodedb

v1.1.0

Published

NodeDB is a simple key-value store for Node.js, built on top of SQLite.

Downloads

40

Readme

NodeDB

NodeDB is a simple key-value store for Node.js, built on top of SQLite.

Installation

You can install NodeDB using npm:

npm install @ajayos/nodedb

Setup

  1. Install NodeDB using npm:
npm install @ajayos/nodedb
  1. Import and create an instance of the DB class with a custom database file path:
const DB = require('@ajayos/nodedb');
const customDBPath = '/path/to/custom/database/file.db';
const nodedb = new DB(customDBPath);
  1. Use the available functions to interact with the database, as demonstrated in the examples below.

Project Description

NodeDB provides an efficient way to manage key-value data in your Node.js applications by leveraging the power of SQLite. It offers a lightweight and embedded database solution suitable for small to medium-sized projects. Whether you need to store user profiles, configuration settings, or any other structured data, NodeDB simplifies the process by providing easy-to-use functions for storing, retrieving, and deleting data.

Functions and Usage

setDB(tableName, rowName, data)

Inserts or updates a row in the specified table with the specified key and data.

Example Usage:

await nodedb.setDB('users', 'ajay', { name: 'Ajay o s', age: 20 });

getDB(tableName, rowName)

Retrieves a row from the specified table with the specified key, or all rows if no key is specified.

Example Usage:

const ajay = await nodedb.getDB('users', 'ajay');
console.log(ajay); // { name: 'Ajay o s', age: 20 }

Example Usage (All Rows):

const allUsers = await nodedb.getDB('users');
console.log(allUsers); // [ { rowName: 'ajay', data: { name: 'Ajay o s', age: 20 } }, ... ]

deleteDB(tableName, rowName)

Deletes a row from the specified table with the specified key, or the entire table if no key is specified.

Example Usage:

await nodedb.deleteDB('users', 'ajay');

Example Usage (Delete Table):

await nodedb.deleteDB('users');

setDATA(tableName, rowName, data: any)

Similar to setDB, but stores data without JSON stringifying it.

Example Usage:

await nodedb.setDATA('metadata', 'version', 1.2);

getDATA(tableName, rowName)

Similar to getDB, but retrieves data without JSON parsing it.

Example Usage:

const version = await nodedb.getDATA('metadata', 'version');
console.log(version); // 1.2

Example Usage (All Rows):

const allVersions = await nodedb.getDATA('metadata');
console.log(allVersions); // [ { rowName: 'version', data: 1.2 }, ... ]

deleteDATA(tableName, rowName)

Similar to deleteDB, but deletes data without JSON parsing it.

Example Usage:

await nodedb.deleteDATA('metadata', 'version');

Example Usage (Delete Table):

await nodedb.deleteDATA('metadata');

Example Here's a complete example of how to use NodeDB to interact with a database:

const DB = require('@ajayos/nodedb');

// Define a custom database file path
const customDBPath = 'mydatabase.sql';

// Create an instance of the DB class
const nodedb = new DB(customDBPath);

async function main() {
  // Set data using setDB
  await nodedb.setDB('users', 'ajay', { name: 'Ajay o s', age: 20 });

  // Get data using getDB
  const ajay = await nodedb.getDB('users', 'ajay');
  console.log('Retrieved Data:', ajay);

  // Delete a specific row using deleteDB
  await nodedb.deleteDB('users', 'ajay');
}

// Run the main function
main().catch((error) => {
  console.error('An error occurred:', error);
});

Note

For functions like deleteDB and deleteDATA, if you provide only the tableName, the entire table will be deleted. To delete a specific row, provide both tableName and rowName.

License

NodeDB is licensed under the Apache License 2.0. See the LICENSE file for details.

Repository

You can find the repository for NodeDB on GitHub at https://github.com/Ajayos/nodedb