2.0.1 • Published 8 years ago
rethink-decl v2.0.1
rethink-decl
Allows you to create RethinkDB queries from options objects. Useful for dealing grabbing querystring parameters and turning them into a query in an API endpoint.
Install
npm install rethink-decl --save
API
decl(model, options)
model
is a thinky model objectoptions
is your object full of optionslimit
- Type: Number
- Controls maximum number of results
offset
- Type: Number
- Controls which offset to start reading from
sort
- Type: Array of field names or comma-separated field names
- Ascending by default
- Prefix field names with - for descending
- Any other options will be treated as a filters
- Returns the query
Be advised: There is no default limit. All results will be returned.
Example
var decl = require('rethink-decl')
var User = thinky.createModel('User', {
id: type.number(),
name: type.string(),
times: {
created: Date,
updated: Date
}
})
// find me 5 users with the name 'Eric'
// start at offset 5
// this is equiv to fetching page #2
decl(User, {
limit: 5,
offset: 5,
name: 'Eric',
sort: [
'-age'
]
}).run(function(err, data){
// do stuff with it
})