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

dreamy-db

v2.0.6

Published

Dreamy-db - A Powerful database for storing, accessing, and managing multiple databases.

Downloads

23

Readme

About

Dreamy-db - A Powerful database for storing, accessing, and managing multiple databases.
Dreamy-db is a powerful node.js module that allows you to interact with the databases very easily.

Why?

  • Object-oriented
  • Feature-rich
  • Performant
  • Configurable
  • 100% Promise-based
  • Speedy and efficient
  • Persistent storage

Features

  • Adapters: By default, data is cached in memory. Optionally, install and utilize a "storage adapter".
  • Namespaces: Namespaces isolate elements within the database to enable useful functionalities.
  • Custom Serializers: Utilizes its own data serialization methods to ensure consistency across various storage backends.
  • Third-Party Adapters: You can optionally utilize third-party storage adapters or build your own.
  • Embeddable: Designed to be easily embeddable inside modules.
  • Data Types: Handles all the JSON types including Buffer.
  • Error-Handling: Connection errors are transmitted through, from the adapter to the main instance; consequently, connection errors do not exit or kill the process.

Installation

Node.js 12.x or newer is required.

Using npm:

$ npm install dreamy-db

Using yarn:

$ yarn add dreamy-db

By default, data is cached in memory. Optionally, install and utilize a "storage adapter".

Officially supported adapters are

  • LevelDB
  • MongoDB
  • NeDB
  • MySQL
  • PostgreSQL
  • Redis
  • SQLite.
$ npm install level # LevelDB
$ npm install mongojs # MongoDB
$ npm install ioredis # Redis

# To use SQL database, an additional package 'sql' must be installed and an adapter
$ npm install sql

$ npm install mysql2 # MySQL
$ npm install pg # PostgreSQL
$ npm install sqlite3 # SQLite

Usage

const { Dreamy } = require('dreamy-db');

// Choose One of the following:
const db = new Dreamy();
const db = new Dreamy('leveldb://path/to/database');
const db = new Dreamy('mongodb://user:pass@localhost:27017/dbname');
const db = new Dreamy('mysql://user:pass@localhost:3306/dbname');
const db = new Dreamy('postgresql://user:pass@localhost:5432/dbname');
const db = new Dreamy('redis://user:pass@localhost:6379');
const db = new Dreamy('sqlite://path/to/database.sqlite');

// Handles connection errors
db.on('error', error => console.error('Connection Error: ', error));

await db.set('foo', 'bar'); // true
await db.find(data => data === 'bar'); // { key: 'foo', value: 'bar' }
await db.get('foo'); // 'bar'
await db.math('dreamy', 'add', 200); // true
await db.has('foo'); // true
await db.all(); // [ { key: 'foo', value: 'bar' } ]
await db.delete('foo'); // true
await db.clear(); // undefined

Namespaces

Namespaces isolate elements within the database to avoid key collisions, separate elements by prefixing the keys, and allow clearance of only one namespace while utilizing the same database.

const users = new Dreamy({ namespace: 'users' });
const members = new Dreamy({ namespace: 'members' });

await users.set('foo', 'users'); // true
await members.set('foo', 'members'); // true
await users.get('foo'); // 'users'
await members.get('foo'); // 'members'
await users.clear(); // undefined
await users.get('foo'); // undefined
await members.get('foo'); // 'members'

Third-Party Adapters

You can optionally utilize third-party storage adapters or build your own. Dreamy will integrate the third-party storage adapter and handle complex data types internally.

const myAdapter = require('./my-adapter');
const database = new Dreamy({ store: myAdapter });

For example, quick-lru is an unrelated and independent module that has an API similar to that of Dreamy.

const QuickLRU = require('quick-lru');

const lru = new QuickLRU({ maxSize: 1000 });
const database = new Dreamy({ store: lru });

Custom Serializers

Dreamy-db handles all the JSON data types including Buffer using its data serialization methods that encode Buffer data as a base64-encoded string, and decode JSON objects which contain buffer-like data, either as arrays of strings or numbers, into Buffer instances to ensure consistency across various backends.

Optionally, pass your own data serialization methods to support extra data types.

const database = new Dreamy({
    serialize: JSON.stringify,
    deserialize: JSON.parse
});

| :warning: warning | Using custom serializers means you lose any guarantee of data consistency. | |----------------------|:---------------------------------------------------------------------------|

Embeddable

Dreamy-db is designed to be easily embeddable inside modules. It is recommended to set a namespace for the module.

class MyModule {
    constructor(options) {
        this.db = new Dreamy({
            uri: typeof opts.store === 'string' && opts.store,
			store: typeof opts.store !== 'string' && opts.store
            namespace: 'mymodule'
        });
    }
}

// Caches data in the memory by default.
const myModule = new MyModule();

// After installing ioredis.
const myModule = new MyModule({ store: 'redis://localhost' });
const myModule = new AwesomeModule({ store: thirdPartyAdapter });

Links