Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.
/ dreamy-db Public archive

πŸ”₯ Dreamy-db - A Powerful database for storing, accessing, and managing multiple database.

License

Notifications You must be signed in to change notification settings

Dreamyplayer/dreamy-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

76 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

dreamy-db

Discord server NPM version NPM downloads Build status Dependencies Patreon

Dreamy-db

About

Dreamy-db - A Powerful database for storing, accessing, and managing multiple databases.
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.

Officially supported adapters

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

  • MongoDB
  • MySQL
  • PostgreSQL
  • Redis
  • SQLite.

Installation

Node.js 12.x or newer is required.

Install dreamy-db using yarn:

yarn add dreamy-db

Or npm:

yarn add dreamy-db

Create an instance of dreamy-db once you've installed dreamy-db and any necessary drivers.

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

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

Make sure to handle connection errors.

db.on('error', error => console.error('Dreamy#Connection Error: ', error));

Usage

(async () => {
  await db
    .set('Profile', {
      id: 1234567890,
      Name: 'Dreamy',
      verified: true,
      tags: ['dreamy-db', 'database'],
      height: 6.2,
      Balance: 450,
      Job: null,
    })
    .then(console.log)
    .catch(console.error);

  // Returns an array that contains the keys of each element.
  await db
    .keys()
    .then(data => console.log(data))
    .catch(console.error);

  // Returns an array that contains the values of each element.
  await db
    .values()
    .then(data => console.log(data))
    .catch(console.error);

  // Gets all the elements from the database.
  await db
    .all()
    .then(data => console.log(data))
    .catch(console.error);

  // Clears all elements from the database.
  await db.clear().then(console.log).catch(console.error);

  // Deletes an element from the database by key.
  await db.delete('profile').then(console.log).catch(console.error);

})(); // Callback

Links