where method
Makes this statement only include rows that match the filter
.
For instance, if you have a table users with an id column, you could select a user with a specific id by using
(select(users)..where((u) => u.id.equals(42))).watchSingle()
Please note that this where call is different to Iterable.where and
Stream.where in the sense that filter
will NOT be called for each
row. Instead, it will only be called once (with the underlying table as
parameter). The result Expression will be written as a SQL string and
sent to the underlying database engine. The filtering does not happen in
Dart.
If a where condition has already been set before, the resulting filter
will be the conjunction of both calls.
For more information, see:
- The docs on expressions,
which explains how to express most SQL expressions in Dart.
If you want to remove duplicate rows from a query, use the
distinct
parameter on DatabaseConnectionUser.select.
Implementation
void where(Expression<bool?> Function(T tbl) filter) {
final predicate = filter(table.asDslTable);
if (whereExpr == null) {
whereExpr = Where(predicate);
} else {
whereExpr = Where(whereExpr!.predicate & predicate);
}
}