36

Working with database at ease: Endb

 4 years ago
source link: https://www.tuicool.com/articles/aEJJbue
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

eyumIf3.png!web

Simple key-value storage for multi adapter.

Officially supported adapters are LevelDB, MongoDB, MySQL, PostgreSQL, Redis, and SQLite. You can also integrate your own adapter .

New to Endb? Check out the Documentation .

Why Endb?

  • High performance, efficiency, and simplicity.
  • Suitable as cache or persistent database.
  • Namespaces
  • Custom Serializers
  • Third-Party Adapters
  • JSON types including Buffer
  • Connection errors are sent through (connection errors won't kill the process).

Installation

npm install endb

By default, data is stored in memory. Optionally, You can install an adapter.

$ npm install level # LevelDB
$ npm install mongojs # MongoDB
$ npm install redis

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

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

Usage

const Endb = require('endb');
const endb = new Endb();
const endb = new Endb('leveldb://path/to/database');
const endb = new Endb('mongodb://user:pass@localhost:27017/dbname');
const endb = new Endb('mysql://user:pass@localhost:3306/dbname');
const endb = new Endb('postgresql://user:pass@localhost:5432/dbname');
const endb = new Endb('redis://user:pass@localhost:6379');
const endb = new Endb('sqlite://path/to/database.sqlite');

// Handles database connection error
endb.on('error', err => console.log('Connection Error: ', err));

await endb.set('foo', 'bar'); // true
await endb.set('exists', true); // true
await endb.set('num', 10); // true
await endb.math('num', 'add', 40); // true
await endb.get('foo'); // 'bar'
await endb.get('exists'); // true
await endb.all(); // { ... }
await endb.has('foo'); // true
await endb.has('bar'); // false
await endb.find(v => v === 'bar'); // { ... }
await endb.delete('foo'); // true
await endb.clear(); // undefined

Links


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK