riak-pb-model

0.3.1 • Public • Published

Riak Protocol Buffers Model

Riak Models (that talk to Riak using Protocol Buffers).

(Uses riak-pb underneath)

Install

$ npm install git://github.com/CrowdProcess/riak-pb-model

Require

var RiakModel = require('riak-pb-model');

Instantiate a Model

A model corresponds to a bucket:

var users = RiakModel({
  bucket: 'users'
});

Here are the valid constructor options:

  • nodes: array containing the nodes it connects to. Each node may contain:
    • host
    • port
  • bucket: the Riak bucket this model will use to store docs in
  • indexes: array of objects, each containing either one of the properties
    • key: a string indicating which doc attribute contains the key
    • composedKey: an array of strings indicating which attributes contain the key

Connecting first

You can create a global Riak connection before instantiating any model:

var riakConnection = RiakModel.connect({
  nodes: [
    {host: 'localhost', port: 8087}
  ]
});

/// now use that connection when instantiating the models

var users = RiakModel(riakConnection, {
  bucket: 'users'
});

Using Indexes

Examples:

var modelOptions = {
  bucket: 'users',
  indexes: [
    { key: 'email'}
  ]
};

var users = RiakModel(modelOptions);

users.findAllByEmail('me@me.com', function(err, users) {
  // ...
});

Use

create(doc, cb); // cb = function(err, doc)

get(id, cb); // cb = function(err, doc)

getAllKeys(cb); // cb = function(err, doc)

getAll(cb); // cb = function(err, docs)

getAllStreaming(); // returns readable stream

update(doc, cb); // cb = function(err, doc)

save(doc, cb); // create or update; cb = function(err, doc)

del(id, cb); // cb = function(err)

del(doc, cb); // cb = function(err)

destroy(id, cb); // cb = function(err)

destroy(doc, cb); // cb = function(err)

removeAll(cb); // cb = function(err)

Dynamic methods, depending on the indexes you defined in the model constructor:

findAllByX(x, cb); // cb = function(err, docs)

findAllByFirstnameAndLastname(firstName, lastName, cb); // cb = function(err, docs)

Readme

Keywords

none

Package Sidebar

Install

npm i riak-pb-model

Weekly Downloads

0

Version

0.3.1

License

none

Last publish

Collaborators

  • pgte