orm-random

v0.0.1
ORM Random instance get/find
orm random

ORM Random instance get/find

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
    });
});
npm i orm-random

Metadata

  • MIT
  • *
  • Diogo Resende
  • released 2/23/2014

Downloads

Maintainers