MEMDB ika (meowDB)
A simple, fast and pure Javascript key-value in memory database for Node JS.
Introduction
This lightweight engine can be used in place of things like LevelDB, Redis while keeping things light and very simple. Internaly, memdb uses json as storage format with an opt-in support for encryption. In order to achieve performance, memdb keeps things in a staging area for fast access. No worries, all the booking is handled for you :). We are developers too, thus we hate keeping tract of things.
Synopsis
const MemDB =const db = '_starwars' encryptionKey: 'secret'dbdb
Installation
$ npm install evansofts-memdb
API
MemDB's API is pretty simple and straigth forward. Some api methods return a promise.
version()
: Get MemDB current versionrevision()
: Get the current database revisionoptions()
: Get the database instance optionsput(keychain, value, loose)
: Save data in the databaseget(keychain, defaultValue)
: Get data from the databaseall()
: Get all data fron the databasedelete(keychain)
: Delete data from the database
NB: What the heck is keychain ?
keychain is a concatenation of multiple object keys to obtain a path for accessing an object property in a deep level. This is a convenient way of puting/getting deeply nested object properties. The following keychain server.dev.host
means accessing the host
property form dev
object which in turn is available in the server
object as a property.
Creating or Opening a database
/*By default, the databse is not encrypted and the staggingoperation size limit is 600 operations; of course you can move it up or down*/const db = 'db_file_path'stagingSize: 600 // maximum staging operation size before flushing the dataencryptionKey: null // optional if you need to encypt your data
Saving data
put(keychain, value, loose)
Parameters | Description |
---|---|
keychain | Path where the data should be stored |
value | The value to be stored |
loose | Will create internal object of the chain if non existant, default to false |
db
Retrieving data
get(keychain, defaultValue)
Parameters | Description |
---|---|
keychain | Path where the data should be retrieved |
defaultValue | The default value to be returned if not found |
db
all()
dball
Deleting data
delete(keychain)
Parameters | Description |
---|---|
keychain | Path where the data should be deleted |
db
Testing
After cloning the repo and installing all dependencies (using npm install
) you can run all tests using mocha:
$ npm test