singleOrNull method

Future<TRow?> singleOrNull()

At most one matching row, or null when none match.

Implementation

Future<TRow?> singleOrNull() async {
  final dialect = await _resolvedDialect();
  final scopes = context.scopeCompiler(state.scope);
  final loader = _loaderFor(session, dialect);
  final rows = await _probeTwo(dialect: dialect, scopes: scopes);
  if (rows.isEmpty) return null;
  if (rows.length > 1) {
    throw MssqlCardinalityException(binding.qualifiedName, 'singleOrNull', 2);
  }
  return (await _attachOn(
    session,
    <TRow>[binding.fromRow(rows.first)],
    dialect: dialect,
    loader: loader,
  )).single;
}