node package manager


Riak Protocol Buffers Model Builder

Riak Protocol Buffers Model

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

(Uses riak-pb underneath)

$ npm install git://
var RiakModel = require('riak-pb-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

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'


var modelOptions = {
  bucket: 'users',
  indexes: [
    { key: 'email'}
var users = RiakModel(modelOptions);
users.findAllByEmail('', function(err, users) {
  // ...