moov-database

1.2.3 • Public • Published

Database

Software License Code Style Downloads Build Status Quality Score Coverage Status

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', '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
// }
//
//
 

CHANGELOG

changelog

CONTRIBUTING

contributing

LICENSE

MIT

Readme

Keywords

Package Sidebar

Install

npm i moov-database

Weekly Downloads

2

Version

1.2.3

License

MIT

Last publish

Collaborators

  • uselessdev