0.0.1 • Published 10 years ago

orm-random v0.0.1

Weekly downloads
3
License
MIT
Repository
-
Last release
10 years ago

ORM Random instance get/find npm.io

This plugin adds random support find for any ORM driver.

Dependencies

Of course you need orm to use it. Other than that, no more dependencies.

Install

npm install orm-random

Usage

Model.getRandom([ conditions ], callback);
Model.findRandom([ conditions ], [ limit = 1 ], callback);

Example

var orm = require("orm");

orm.connect("mysql://username:password@host/database", function (err, db) {
    if (err) throw err;

    db.use(fts);

    db.use(require("orm-random"));

    var Person = db.define("person", {
        name      : String,
        surname   : String,
        age       : Number
    });

    Person.findRandom(10, { age: orm.gte(18) }, function (err, people) {
        // returns 10 random people (might have dups) with age at least 18
    });
});