UNPKG

dbjsond

Version:

Quick and easy database for Node.js.

97 lines (71 loc) 1.98 kB
# dbjsond Quick and easy embeddable database for Node.js. The module stores all the data within the in-memory representation and optionally saves it in JSON file. [Github Link](https://github.com/devlix1/dbjsond) ## Requirements This module requires Node.js v6.* ## Install `npm install dbjsond` ## Example See **example** folder for more complex examples. #### In-Memory ```javascript const dbjsond = require('dbjsond'), db = new dbjsond(':memory'); db.add('Name', 'Value').add('Name2', 'Value2'); // {'Name': 'Value', 'Name2': 'Value2'} db.get('Name'); // return Value db.remove('Name').remove('Name2'); // {} ``` #### File ```javascript const dbjsond = require('dbjsond'), db = new dbjsond('/path/to/json'); db.add('Name', 'Value').add('Name2', 'Value2'); // {'Name': 'Value', 'Name2': 'Value2'} db.get('Name'); // return Value db.save(); ``` ## API ```javascript db.add(Name, Value, Collection = optional) // returns this ``` Adds a named value. ```javascript db.get(Name, Collection = optional) // returns value ``` Returns a key value. ```javascript db.getAll(Collection = optional) // returns {} ``` Returns a full temp object or collection. ```javascript db.remove(Name, Collection = optional) // returns this ``` Removes a key. ```javascript db.setCollection(Collection) // returns this ``` Sets collection name (which is used by **db.add() db.get() db.remove()**). ```javascript db.unsetCollection() // returns this ``` Unsets collection name. ```javascript db.removeCollection(Collection) // returns this ``` Removes collection from the database object. ```javascript db.save() ``` Saves database object in file. ```javascript db.autosave(data, timer = optional) ``` Starts database autosaving. **NOTE** data must be db._tempMemory. ## Contributor * [Devlix](https://vk.com/app_data) ## License `dbjsond` is MIT licensed.