range
Range is used in combination with where
and and
clauses in Dream.
range supports start, end, or start and end values
import { range } from '@rvoh/dream'
// search Recipes with a rating of at least 3
await Recipe.where({ rating: range(3) }).count()
// search Recipes with a rating of 2 or less
await Recipe.where({ rating: range(null, 2) }).count()
// search Recipes with a rating between 2 and 4, inclusive
await Recipe.where({ rating: range(2, 4) }).count()
range supports CalendarDate, DateTime, and number values
import { range } from '@rvoh/dream'
await user
.associationQuery('pets')
.where({
adoptedOn: range(
CalendarDate.today().minus({ months: 2 }),
CalendarDate.today().minus({ month: 1 })
),
})
.order({ adoptedOn: 'desc' })
.all()
await user
.associationQuery('pets')
.where({
adoptedOn: range(
DateTime.now().minus({ months: 2 }),
DateTime.now().minus({ month: 1 })
),
})
.order({ adoptedOn: 'desc' })
.all()
range can be used in association declaration and
statements
const deco = new Decorators<typeof Post>()
export default class Post extends ApplicationModel {
...
@deco.HasMany(Comment, { and: { createdAt: () => range(CalendarDate.today().minus({ weeks: 2 })) } })
public recentComments: Comment[]
}