node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »



Sukeru is an Object Document Mapper for Riak.


First we need to connect to the database (localhost by default):

sukeru.connect(function() {
    // Inside this we can define our models and do our queries...     

Model definition

Let's define a basic User model:

var User = sukeru.model('User', function() {

Data types

The currently available data types are:

  • string
  • boolean
  • date

Accessing a Model

var User = sukeru.model('User');


Now that the User model is created, we can create a new user and than save it to the database:

var john = new User(); = "John"; = "";
john.password = "my secret password"; {
        return console.log(err);
    console.log("The user has been successfully created", john);
    console.log("It should have a new generated id:",;

Let's find a user by id:

User.findById("aNIdToFind", function(err, user) {
        return console.log(err);
    console.log("A user was found", user);

To delete this user:

john.remove(function(err) {
   console.log("John should not exist anymore in the database");

To delete a user by its id:

User.delete("aNIdToDelete", function(err) {
   console.log("This user should not exist anymore in the database");


You can specify validation rules for each field this way:

var User = sukeru.model('User', function() {
                           .after(new Date(2012, 01, 01))
                           .before(new Date(2015, 01, 01));

You can also pass a default value as a second argument of the property type:'birthday', new Date());
this.string('name', 'John');

Defining methods and statics

var User = sukeru.model('User', function() {
    this.methods.comparePassword = function(password) {
        return (this.password === password);
    this.statics.findByName = function(name, callback) {{
            q: "name_s:"+name
        }, cb);
// Example usage 
// Static function 
User.findByName("John", function(err, users) {
    // Do something here with your users 
// Instance level methods 
var user = new User(); = "test";
user.password = "secret";
user.comparePassword("falsepassword"); // should be false 
user.comparePassword("secret"); // should be true 


Riak has a built-in Solr search engine.

Solr needs a schema to define each fields name and types. By default, Riak provides us a default schema. For strings to be indexed we need to add the suffixe: "_s"

Let's say we want to be able to search for the name of a user. We can modify the model definition like this:

var User = sukeru.model('User', function() {

To search for an object we can run a Solr query:{
    q: "name_s:John",
    rows: 10
}, function(err, users) {
    console.log("Here we have our results", users)

Note : For now you are only able to use the default search schema provided by Riak's Team for Solr (thus the suffix "_s")