orm-random

0.0.1 • Public • Published

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
    });
});

Readme

Keywords

Package Sidebar

Install

npm i orm-random

Weekly Downloads

3

Version

0.0.1

License

MIT

Last publish

Collaborators

  • dresende