JSON file store
A simple JSON file store for node.js.
WARNING:
Don't use it if you want to persist a large amount of objects.
Use a real DB instead.
Install
npm install jfs --save
Usage
var Store = require("jfs");
var db = new Store("data");
var d = {
foo: "bar"
};
db.save("anId", d, function(err){
});
db.save(d, function(err, id){
});
var id = db.saveSync("anId", d);
db.get("anId", function(err, obj){
})
var prettyDB = new Store("data",{pretty:true});
var id = prettyDB.saveSync({foo:{bar:"baz"}});
{
"foo": {
"bar": "baz"
}
}
{"foo":{"bar":"baz"}}
var obj = db.getSync("anId");
db.all(function(err, objs){
});
var objs = db.allSync()
db.delete("myId", function(err){
});
db.delete("myId");
Single file DB
If you want to store all objects in a single file,
set the type
option to memory
:
var db = new Store("data",{type:'single'});
or point to a JSON file:
var db = new Store("./path/to/data.json");
In memory DB
If you don't want to persist your data, you can set type
to memory
:
var db = new Store("data",{type:'memory'});
Tests
npm test
License
This project is licensed under the MIT License.