querySingle method

Future<Map<String, Object?>> querySingle(
  1. String sql, {
  2. Object parameters = const <String, Object?>{},
  3. MssqlQueryOptions options = MssqlQueryOptions.defaults,
  4. Duration? timeout,
  5. MssqlCancellationToken? cancellationToken,
})
inherited

Exactly one row, as a map. More than one is an error, not a choice.

Implementation

Future<Map<String, Object?>> querySingle(
  String sql, {
  Object parameters = const <String, Object?>{},
  MssqlQueryOptions options = MssqlQueryOptions.defaults,
  Duration? timeout,
  MssqlCancellationToken? cancellationToken,
}) async {
  final rows = await queryRows(
    sql,
    parameters: parameters,
    options: options.limitedTo(2),
    timeout: timeout,
    cancellationToken: cancellationToken,
  );
  if (rows.isEmpty) throw const MssqlNoRowsException();
  if (rows.length > 1) throw const MssqlMultipleRowsException();
  return rows.single;
}