where
The where method returns an instance of a Query (tethered by type generics back to the originating Dream class) which can then be chained with many statements before final execution.
await User.where({ email: null }).all()
// [User{ email: null }, User{ email: null }, ...]
Basic usage
where statements will by default compare with strict equivalence. However, it is also possible to pass special expressions. The example below demonstrates the application of an ops.ilike query being applied to your query.
await User.where({ email: ops.ilike('%burpcollaborator.net%') }).destroy()
// 3
For more info on
opsexpressions, see the ops guide.
Array values (IN clause)
If an array is passed as a value to a non-array field, the query will select any of the values provided in the array (SQL IN clause):
await User.where({ email: ['hi@hi', 'bye@bye'] }).all()
// [User{ email: 'hi@hi' }, User{ email: 'bye@bye' }]
Associations
BelongsTo associations can also be provided as arguments. Polymorphic associations will also have their type fields extracted into the query.
await Pet.where({ user }).count()