npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sukeru

v0.1.0

Published

An Object Document Mapper for Riak

Readme

Overview

Sukeru is an Object Document Mapper for Riak.

Usage

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() {
    this.string('name');
    this.string('email');
    this.string('password'); 
});

Data types

The currently available data types are:

  • string
  • boolean
  • date

Accessing a Model

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

Methods

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.name = "John";
john.email = "[email protected]";
john.password = "my secret password";
john.save(function(err) {
    if(err)
        return console.log(err);
    console.log("The user has been successfully created", john);
    console.log("It should have a new generated id:", john.id);
});

Let's find a user by id:

User.findById("aNIdToFind", function(err, user) {
    if(err)
        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");
});

Validation

You can specify validation rules for each field this way:

var User = sukeru.model('User', function() {
    this.string('name').required();
    this.string('email').required()
                        .email();
    this.string('password').required()
                           .minLength(6)
                           .maxLength(16); 
    this.date('birthday').required()
                           .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:

this.date('birthday', new Date());
this.string('name', 'John');

Defining methods and statics

var User = sukeru.model('User', function() {
    this.string('name_s');
    this.string('email');
    this.string('password'); 
    
    this.methods.comparePassword = function(password) {
        return (this.password === password);
    };
    this.statics.findByName = function(name, callback) {
        this.search({
            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();
user.email = "test";
user.password = "secret";
user.comparePassword("falsepassword"); // should be false
user.comparePassword("secret"); // 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.model('User', function() {
    this.string('name_s')
    this.string('email');
    this.string('password'); 
});

To search for an object we can run a Solr query:

User.search({
    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")