selectOnly<T extends HasResultSet, R> method

JoinedSelectStatement<T, R> selectOnly<T extends HasResultSet, R>(
  1. ResultSetImplementation<T, R> table, {
  2. bool distinct = false,
})

Starts a complex statement on table that doesn't necessarily use all of table's columns.

Unlike select, which automatically selects all columns of table, this method is suitable for more advanced queries that can use table without using their column. As an example, assuming we have a table comments with a TextColumn content, this query would report the average length of a comment:

Stream<num> watchAverageCommentLength() {
  final avgLength = comments.content.length.avg();
  final query = selectOnly(comments)
    ..addColumns([avgLength]);

  return query.map((row) => row.read(avgLength)).watchSingle();
}

While this query reads from comments, it doesn't use all of it's columns (in fact, it uses none of them!). This makes it suitable for selectOnly instead of select.

The distinct parameter (defaults to false) can be used to remove duplicate rows from the result set.

For simple queries, use select.

See also:

Implementation

JoinedSelectStatement<T, R> selectOnly<T extends HasResultSet, R>(
    ResultSetImplementation<T, R> table,
    {bool distinct = false}) {
  return JoinedSelectStatement<T, R>(this, table, [], distinct, false, false);
}