mini-dbx

1.0.2 • Public • Published

mini-dbx

more in mini-db.

Install

npm install mini-dbx

API

insert

var storage = require('mini-dbx');
var db = storage('./storage/db.json');
db.insert('people', { name: 'Jim', age: 27 },function(err,inserted){
    if(!err) console.log(inserted);
});

select

var storage = require('mini-dbx');
var db = storage('./storage/db.json');
db.select('people').forEach(function(item){
    console.log(item.name,item.age);
});

select(filter)

代码片段中,$表示值本身,#表示值在数组中的索引

var storage = require('mini-dbx');
var db = storage('./storage/db.json');
db.select('people', '$.age==27').forEach(function (item) {
   console.log(item.name + ':' + item.age);
});
db.select('people', '#==0',function(err,list){
    if(err){return;}
    list.forEach(function(item){
        console.log(item.name,':',item.age);
    });
});


update

var storage = require('mini-dbx');
var db = storage('./storage/db.json');
db.update('people', { name: 'Kim', age: 27 }, '$.age==27',function(err,updated){
    if(!err) console.log(updated);
});

remove

var storage = require('mini-dbx');
var db = storage('./storage/db.json');
db.remove('people', '#==0',function(err,removed){
    if(!err) console.log(removed);
});

Readme

Keywords

Package Sidebar

Install

npm i mini-dbx

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

9.29 kB

Total Files

6

Last publish

Collaborators

  • apporoad