ee-jsondb
v1.0.3
Published
A node.js module for lightweight json database.
Downloads
12
Readme
ee-jsondb
ee-jsondb is a lightweight json database, it`s extracting and rebuild from egg-electron project
Installation
npm i ee-jsondb
Usage
const Storage = require('ee-jsondb');
API List
connection(database)
- database [String] - database json file name
If no this database will auto create
jsondatabse
const jdb = Storage.connection('demo');
jdb.setItem()
jdb.setItem('test_key', {name:'xiaoming'})
jdb.getItem()
jdb.getItem('test_key')
jdb.db
jsondb object instance
db.defaults({posts: [], user: {}, count: 0})
.write();
db.get('posts')
.push({id: 1, title: 'jsondb is awesome'})
.write()
db.set('user.name', 'typicode')
.write()
db.update('count', n => n + 1)
.write()
The result data:
{
"posts": [
{
"id": 1,
"title": "jsondb is awesome"
}
],
"user": {
"name": "typicode"
},
"count": 1
}
- You can use lodash math, example: _.get() or _.find():
db.get('users')
.find({sex: 'male'})
.value()
- query only use .value() or .write() then excute. You can use lodash math
db.has('users')
.value()
db.set('users', [])
.write()
db.get('users')
.filter({sex: 'male'})
.sortBy('age')
.take(5)
.value()
db.get('users')
.map('name')
.value()
db.get('users')
.size()
.value()
db.get('users[0].name')
.value()
db.get('users')
.find({name: 'Tom'})
.assign({name: 'Tim'})
.write()
db.unset('users.name')
.write()
db.get('users')
.cloneDeep()
.value()