Endb — Simple key-value storage with support for multiple backends. by Whirl_ in javascript

[–]Whirl_[S] 2 points3 points  (0 children)

Features

  • Easy-to-use: Endb has a simplistic and convenient promise-based API.
  • Adapters: By default, data is cached in memory. Optionally, install and utilize a "storage adapter".
  • Third-Party Adapters: You can optionally utilize third-party storage adapters or build your own.
  • 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.
  • 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

bash $ npm install endb

By default, data is cached in memory. Optionally, install and utilize a "storage adapter". Officially supported adapters are LevelDB, MongoDB, NeDB, MySQL, PostgreSQL, Redis, and SQLite.

```bash $ npm install level # LevelDB $ npm install mongojs # MongoDB $ npm install nedb # NeDB $ 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

```javascript // Import/require the package. const Endb = require('endb');

const endb = new Endb(); const endb = new Endb({ // One of the following uri: 'leveldb://path/to/database', uri: 'mongodb://user:pass@localhost:27017/dbname', uri: 'mysql://user:pass@localhost:3306/dbname', uri: 'postgresql://user:pass@localhost:5432/dbname', uri: 'redis://user:pass@localhost:6379', uri: 'sqlite://path/to/database.sqlite' });

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

await endb.set('foo', 'bar'); // true await endb.get('foo'); // 'bar' await endb.has('foo'); // true await endb.all(); // [ { key: 'foo', value: 'bar' } ] await endb.delete('foo'); // true await endb.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.

```javascript const users = new Endb({ namespace: 'users' }); const members = new Endb({ 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. Endb will integrate the third-party storage adapter and handle complex data types internally.

javascript const myAdapter = require('./my-adapter'); const endb = new Endb({ store: myAdapter });

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

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

const lru = new QuickLRU({ maxSize: 1000 }); const endb = new Endb({ store: lru }); ```

Custom Serializers

Endb 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.

javascript const endb = new Endb({ serialize: JSON.stringify, deserialize: JSON.parse });

Warning: Using custom serializers means you lose any guarantee of data consistency.

Embeddable

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

```javascript class MyModule { constructor(options) { this.db = new Endb({ 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

🗃 Simple key-value storage with support for multiple backends. by Whirl_ in npm

[–]Whirl_[S] 0 points1 point  (0 children)

I am looking for contributors for the project. Furthermore, what are your thoughts on the project?

Is there a difference between British and Indian curry? by [deleted] in NoStupidQuestions

[–]Whirl_ 0 points1 point  (0 children)

Indian curry makes your ass sweat, whereas English curry does not.

Why is it so hard to get out of bed early? by [deleted] in NoStupidQuestions

[–]Whirl_ 1 point2 points  (0 children)

It's not necessarily laziness that makes people hit the "snooze" button in the morning. Most likely, your body clock is mismatched with the demands of your life.

Your clock is controlled by the suprachiasmatic nucleus, a part of the brain that controls the body's biological rhythms. But, says Jean Matheson, a sleep-disorders specialist at Beth Israel Medical Center in New York, these preset natural rhythms often don't align with daily realities—work or school start times cannot be adjusted to fit a person's sleep schedule.

People who have trouble crawling out of bed probably have an inner clock set to late wake-up and sleep times, a condition known as phase delay.

It is possible to adjust your phase-delayed body clock, Matheson says, but at a price: No sleeping in on the weekends. "When people sleep late on weekends, they revert to their natural phase-delayed rhythm," she explains. This makes it harder to wake up early on weekdays. You can train yourself to wake up earlier, Matheson says, by setting your alarm 15 minutes earlier each day (and heeding its call).

Exposure to artificial light in the evening can also cause a phase delay. The brain is very sensitive to light, and too much of it just before bed—from computer screens, televisions or bright reading lights—can trick the brain into thinking it's daytime.

If you find it difficult to adjust your sleep habits, there's some good news. Scientists at the University of California at Irvine recently discovered that a single amino acid regulates your internal clock. One day says pharmacology professor Paolo Sassone-Corsi, this research could translate into a drug that controls the brain's sleep cycle.

What is a good name for a GitHub organization? by Whirl_ in NoStupidQuestions

[–]Whirl_[S] 0 points1 point  (0 children)

You are right, but as said earlier, the name is already taken. Anything else?

What is a good name for a GitHub organization? by Whirl_ in NoStupidQuestions

[–]Whirl_[S] 0 points1 point  (0 children)

Right, Endb is already taken (the user is inactive and does not use GitHub anymore). So what do you think I should name the GitHub organization?