selectFirstByQuery method
FutureOr<O?>
selectFirstByQuery(
- String query, {
- Object? parameters,
- List? positionalParameters,
- Map<
String, Object?> ? namedParameters, - Transaction? transaction,
- int? offset,
- int? page,
- bool? orderByID,
- OrderDirection? orderDirection,
- EntityResolutionRules? resolutionRules,
override
Ordering and pagination:
limit: the maximum number of returned entities. Also the page size ofpage.offset: the return offset, for pagination.page: the 1-based page to return, an ergonomic alternative tooffset: it resolves to(page - 1) * limit. Requires a positivelimit, and can't be combined withoffset. See resolveSelectOffset.orderByID: iftruethe result is ordered by the table ID column, automatically resolved from the table scheme (TableScheme.idFieldName) or from EntityHandler.idFieldName. Defaults totruewhenoffsetis defined, since a paginated select needs a stable order to be correct, and, with a SQL database, also whenlimitis defined (which rows an unorderedLIMITreturns is undefined). Passfalseto opt out.orderDirection: the OrderDirection of the ordering, OrderDirection.ascending by default. Ignored while the ordering is not active (seeorderByID).
A query over a to-many relationship returns (and counts, and paginates)
each entity once: with a SQL database, its JOINs are in a subquery of
the matching IDs. Note that 2 conditions over the same to-many
relationship (roles.type == "a" && roles.type == "b") are, on SQL,
over the same joined row, and in memory each over any related entity.
Implementation
@override
FutureOr<O?> selectFirstByQuery(
String query, {
Object? parameters,
List? positionalParameters,
Map<String, Object?>? namedParameters,
Transaction? transaction,
int? offset,
int? page,
bool? orderByID,
OrderDirection? orderDirection,
EntityResolutionRules? resolutionRules,
}) => selectByQuery(
query,
parameters: parameters,
positionalParameters: positionalParameters,
namedParameters: namedParameters,
transaction: transaction,
limit: 1,
// The page size of a "first" select is 1, so `page: n` is the Nth entity:
offset: resolveSelectOffset(page: page, offset: offset, limit: 1),
orderByID: orderByID,
orderDirection: orderDirection,
resolutionRules: resolutionRules,
).resolveMapped((result) => result.firstOrNull);