Package Exports
- moov-database
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (moov-database) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Database
A simple json database storage.
Get Started
Install the package
$ [sudo] npm install --save moov-databaseBasic 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', 'donkey@mydonkeymail.com')
// Or you can chain methods...
db
.add('username', 'donkey')
.add('useremail', 'donkey@mydonkeymail.com')
console.log(db.data) // {username: 'donkey', useremail: 'donkey@mydonkeymail.com'}
.massive()
Using the massive method you can store an whole object at once to your database
//...
db.massive({
users: [
{name: 'donkey', email: 'donkey@mydonkeymail.com'},
{name: 'cow', email: 'cow@mycowmail.com'}
]
})
console.log(db.data)
// {
// 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.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: 'donkey@mydonkeymail.com'},
// {name: 'cow', email: 'donkey@mycowmail.com'}
// ]
Example:
const database = require('moov-database')
const db = database.setFile('./users.json')
db
.massive({
users: [
{name: 'donkey', email: 'donkey@mydonkey.com'},
{name: 'cow', email: 'cow@mycow.com'}
]
})
.add('count_users', db.get('users').length)
.store()
db.get()
// will return
//
// {
// users: [
// {name: 'donkey', email: 'donkey@mydonkey.com'},
// {name: 'cow', email: 'cow@mycow.com'}
// ],
// count_users: 2
// }
//
//