selectOnly<T extends HasResultSet, R> method
- ResultSetImplementation<
T, R> table, { - bool distinct = false,
- bool includeJoinedTableColumns = true,
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 = selectWithoutResults(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.
The includeJoinedTableColumns parameter (defaults to true) can be used
to determinate join statement's useColumns parameter default value. Set
it to false if you don't want to include joined table columns by default.
If you leave it on true and don't set useColumns parameter to false in
join declarations, all columns of joined table will be included in query
by default.
For simple queries, use select.
See also:
- the documentation on aggregate expressions
- the documentation on group by
Implementation
JoinedSelectStatement<T, R> selectOnly<T extends HasResultSet, R>(
ResultSetImplementation<T, R> table,
{bool distinct = false,
bool includeJoinedTableColumns = true}) {
return JoinedSelectStatement<T, R>(
resolvedEngine, table, [], distinct, false, includeJoinedTableColumns);
}