https://github.com/dresende/node-orm-random
ORM Random instance get/find
https://github.com/dresende/node-orm-random
Last synced: 11 months ago
JSON representation
ORM Random instance get/find
- Host: GitHub
- URL: https://github.com/dresende/node-orm-random
- Owner: dresende
- Created: 2014-02-23T22:52:20.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-02-23T22:53:02.000Z (almost 12 years ago)
- Last Synced: 2025-02-02T03:18:42.843Z (11 months ago)
- Size: 97.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## ORM Random instance get/find [](https://npmjs.org/package/orm-random)
This plugin adds random support find for any [ORM](http://dresende.github.io/node-orm2) driver.
## Dependencies
Of course you need `orm` to use it. Other than that, no more dependencies.
## Install
```sh
npm install orm-random
```
## Usage
```js
Model.getRandom([ conditions ], callback);
Model.findRandom([ conditions ], [ limit = 1 ], callback);
```
## Example
```js
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
});
});
```