Simple bucket/key-value interface
Register a connection and give it a name
var simpleDB = require("simple-db")
, riak = require("simple-db-riak")
, redis = require("simple-db-redis")
, mongo = require("simple-db-mongo");
simpleDB
.use("riak", riak(process.env.RIAK_URL))
.use("mongo", mongo("mongodb://user:pass@localhost/my-db"))
.use("redis", redis({host: "...", port: 1234}));
Set the default adapter
simpleDB
.use("riak", riak(...))
.use("mongo", riak(...));
simpleDB.default("mongo");
var db = simpleDB(); // db uses `mongo` adapter
var db2 = simpleDB("riak"); // db uses `riak` adapter
var db = require("simple-db")("riak");
db.buckets()
.end(function(res){
console.log(res.body) // ['food']
})
// db.count(bucket)
db.count("food")
.end(function(res){
console.log(res.body) // 3
})
// db.keys(bucket)
db.keys("food")
.end(function(res){
console.log(res.body) // ['pizza', 'steak', 'burger-key']
})
// db.get(bucket, key)
db.get("food", "pizza")
.end(function(err, res){
console.log(res.body); // {name: "pizza", toppings: ["pepperoni"]}
});
// db.head(bucket, key)
db.head("food", "steak")
.end(function(err, res){
console.log(res.metadata); // {...}
});
// db.post(bucket)
db.post("food")
.send({name: "casserole"})
.end(function(res){
console.log(res.key); // generated on the server
});
// db.put(bucket, key)
db.put("food", "burger-key")
.send({name: "burger", toppings: ["tomatoes","cheese"]})
.end(function(res){
console.log(res.key); // burger-key
});
// db.remove(bucket, key)
db.remove("food", "broccoli")
.end(function(res){
console.log(res.ok) // true
});
// db.exists(bucket, key)
db.exists("food", "apple")
.end(function(res){
console.log(res.body) // false
});