moov-database
v1.2.3
Published
Database for moov
Downloads
30
Readme
Database
A simple json database storage.
Get Started
Install the package
$ [sudo] npm install --save moov-database
Basic Usage
const db = require('moov-database')
db
.setFile('path/to/your/db.json')
.add('user', 'uselessdev')
.store()
API
.setFile(path/to/your/database.json)
The setFile
method allow you to set a path for one database per time.
//...
db.seFile('./users.json')
console.log(db.database) // ./users.json
.add(key, value)
Using the add
method you can push a new data to your database
//...
db.add('username', 'donkey')
db.add('useremail', '[email protected]')
// Or you can chain methods...
db
.add('username', 'donkey')
.add('useremail', '[email protected]')
console.log(db.data) // {username: 'donkey', useremail: '[email protected]'}
.massive()
Using the massive
method you can store an whole object at once to your database
//...
db.massive({
users: [
{name: 'donkey', email: '[email protected]'},
{name: 'cow', email: '[email protected]'}
]
})
console.log(db.data)
// {
// users: [
// {name: 'donkey', email: '[email protected]'},
// {name: 'cow', email: '[email protected]'}
// ]
// }
.store()
The store
method will save the stored data in to a .json
file
//...
db.store()
.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.get('users')
// [
// {name: 'donkey', email: '[email protected]'},
// {name: 'cow', email: '[email protected]'}
// ]
Example:
const database = require('moov-database')
const db = database.setFile('./users.json')
db
.massive({
users: [
{name: 'donkey', email: '[email protected]'},
{name: 'cow', email: '[email protected]'}
]
})
.add('count_users', db.get('users').length)
.store()
db.get()
// will return
//
// {
// users: [
// {name: 'donkey', email: '[email protected]'},
// {name: 'cow', email: '[email protected]'}
// ],
// count_users: 2
// }
//
//