Database
A simple json database storage.
Get Started
Install the package
$ [sudo] npm install --save moov-database
Basic Usage
const db = db
API
.setFile(path/to/your/database.json)
The setFile
method allow you to set a path for one database per time.
//... db console // ./users.json
.add(key, value)
Using the add
method you can push a new data to your database
//... dbdb // Or you can chain methods... db console // {username: 'donkey', useremail: 'donkey@mydonkeymail.com'}
.massive()
Using the massive
method you can store an whole object at once to your database
//... db console// {// users: [// {name: 'donkey', email: 'donkey@mydonkeymail.com'},// {name: 'cow', email: 'donkey@mycowmail.com'}// ]// }
.store()
The store
method will save the stored data in to a .json
file
//... db
.get()
Using the get
method you can retrieve all data stored in database, or you can retrieve a single result by passing his key
name
//... db// [// {name: 'donkey', email: 'donkey@mydonkeymail.com'},// {name: 'cow', email: 'donkey@mycowmail.com'}// ]
Example:
const database = const db = database db db// will return//// {// users: [// {name: 'donkey', email: 'donkey@mydonkey.com'},// {name: 'cow', email: 'cow@mycow.com'}// ],// count_users: 2// }////