Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    orm-randompublic

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

    Keywords

    install

    npm i orm-random

    Downloadslast 7 days

    0

    version

    0.0.1

    license

    MIT

    repository

    github.com

    last publish

    collaborators

    • avatar