Overview
Sukeru is an Object Document Mapper for Riak.
Usage
First we need to connect to the database (localhost by default):
sukeru;
Model definition
Let's define a basic User model:
var User = sukeru;
Data types
The currently available data types are:
- string
- boolean
- date
Accessing a Model
var User = sukeru;
Methods
Now that the User model is created, we can create a new user and than save it to the database:
var john = ;johnname = "John";johnemail = "john@example.com";johnpassword = "my secret password";john;
Let's find a user by id:
User;
To delete this user:
john;
To delete a user by its id:
User;
Validation
You can specify validation rules for each field this way:
var User = sukeru;
You can also pass a default value as a second argument of the property type:
this;this;
Defining methods and statics
var User = sukeru; // Example usage // Static functionUser; // Instance level methodsvar user = ;useremail = "test";userpassword = "secret";user; // should be falseuser; // should be true
Search
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;
To search for an object we can run a Solr query:
User;
Note : For now you are only able to use the default search schema provided by Riak's Team for Solr (thus the suffix "_s")