single method

Future<TRow> single()

Exactly one matching row.

Zero rows is MssqlRowNotFoundException; two or more is MssqlCardinalityException. first() is the ordered "take one" reading; this one is a uniqueness assertion.

Implementation

Future<TRow> single() 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) {
    throw MssqlRowNotFoundException(binding.qualifiedName, null);
  }
  if (rows.length > 1) {
    throw MssqlCardinalityException(binding.qualifiedName, 'single', 2);
  }
  return (await _attachOn(
    session,
    <TRow>[binding.fromRow(rows.first)],
    dialect: dialect,
    loader: loader,
  )).single;
}