existsWhere method

Future<bool> existsWhere(
  1. MssqlCondition where
)

Whether any scoped row matches where, using SELECT TOP 1.

Implementation

Future<bool> existsWhere(MssqlCondition where) async {
  _checkDecimalAgreement();
  var query = MssqlQuery.fromParts(binding.nameParts, ref: binding.sourceRef);
  for (final condition in _scopeConditions) {
    query = query.where(condition);
  }
  final statement = query
      .where(where)
      .top(1)
      .select(<MssqlExpression>[const MssqlProbeLiteral()])
      .compile(dialect: await _dialect());
  final rows = await session.queryTypedRows(
    statement.sql,
    parameters: statement.parameters,
    options: options,
    timeout: options.timeout,
    cancellationToken: options.cancellationToken,
    // Compiled reads are retryable unless raw SQL changes classification.
    retry: statement.readRetry,
  );
  return rows.isNotEmpty;
}