Skip to content

Latest commit

 

History

History
139 lines (112 loc) · 2.4 KB

README.md

File metadata and controls

139 lines (112 loc) · 2.4 KB

simple-db Build Status

Simple bucket/key-value interface

Usage

Adapters

API

use

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}));

default

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

one-line

var db = require("simple-db")("riak");

buckets

db.buckets()
  .end(function(res){
    console.log(res.body) // ['food']
  })

count

// db.count(bucket)
db.count("food")
  .end(function(res){
    console.log(res.body) // 3
  })

keys

// db.keys(bucket)
db.keys("food")
  .end(function(res){
    console.log(res.body) // ['pizza', 'steak', 'burger-key']
  })

get

// db.get(bucket, key)
db.get("food", "pizza")
  .end(function(err, res){
    console.log(res.body); // {name: "pizza", toppings: ["pepperoni"]}
  });

head

// db.head(bucket, key)
db.head("food", "steak")
  .end(function(err, res){
    console.log(res.metadata); // {...}
  });

post

// db.post(bucket)
db.post("food")
  .send({name: "casserole"})
  .end(function(res){
    console.log(res.key); // generated on the server
  });

put

// db.put(bucket, key)
db.put("food", "burger-key")
  .send({name: "burger", toppings: ["tomatoes","cheese"]})
  .end(function(res){
    console.log(res.key); // burger-key
  });

remove

// db.remove(bucket, key)
db.remove("food", "broccoli")
  .end(function(res){
    console.log(res.ok) // true
  });

exists

// db.exists(bucket, key)
db.exists("food", "apple")
  .end(function(res){
    console.log(res.body) // false
  });