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 Places that sleep at least 3 people
await Place.where({ sleeps: range(3) }).count()
// search Places that sleep 2 or fewer people
await Place.where({ sleeps: range(null, 2) }).count()
// search Places that sleep between 2 and 4 people, inclusive
await Place.where({ sleeps: 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[]
}