first method
Future<MssqlRow?>
first(
- MssqlSession session, {
- MssqlDialect dialect = MssqlDialect.sql2012,
- Duration? timeout,
- MssqlCancellationToken? cancellationToken,
- MssqlQueryOptions options = MssqlQueryOptions.defaults,
The first row, or null.
Narrowed to one row so that the server stops early rather than
materialising a result the caller discards. Which clause does the
narrowing depends on what the query already carries: a page keeps its
offset and asks for one row of it, and everything else — including a
top() wider than one — becomes TOP (1). The two are never combined,
which SQL Server rejects anyway.
Implementation
Future<MssqlRow?> first(
MssqlSession session, {
MssqlDialect dialect = MssqlDialect.sql2012,
Duration? timeout,
MssqlCancellationToken? cancellationToken,
MssqlQueryOptions options = MssqlQueryOptions.defaults,
}) async {
final start = offset;
final limited = start == null ? top(1) : paged(offset: start, rows: 1);
final rows = await limited.get(
session,
dialect: dialect,
timeout: timeout,
cancellationToken: cancellationToken,
options: options,
);
return rows.isEmpty ? null : rows.first;
}