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) {
// ...
});