where method

UpdateStatement<Row, RS> where(
  1. Expression<bool> filter(
    1. RS tbl
    )
)
inherited

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

Self where(Expression<bool> Function(RS tbl) filter) {
  final predicate = filter(resultSet.asSelfType());

  if (whereClause == null) {
    whereClause = WhereClause(predicate);
  } else {
    whereClause = WhereClause(whereClause!.condition & predicate);
  }

  return asSelf();
}