lagret
Persistant db.json on the client. The classic array of objects. Uses localstorage. Modelled on the mongoDB API. Values behave like you would expect from the json API. Unique id:s are created if none are passed. Optionally create your own by the helper .id()
or by other means. Always use _id
for the key and make them strings. .add
, .remove
and .update
return an object with the operation specified and records affected.
install
$ npm i lagret
usage
// init by passing an array of collectionsvar db = 'items' 'users';// fetchvar data = dbusers;// add one by passing an object. Pass array to add many.var added = dbusers;// remove one by passing an id. Pass array to remove manyvar removed = dbusers;// update one by passing an id and an object with data// Pass array to update many// Pass only an object with data to update all recordsvar updated = dbusers;// erase all datadbusers;// return number of recordsvar n = dbusers;
TODOs
- npm
- continue testing
- sort
- optional cb
- update by regex
Licence
MIT