baseQuery method

MssqlQuery baseQuery(
  1. MssqlScopeSelection selection, {
  2. MssqlScopeCompiler? scopes,
})

The base SELECT for this table, with scope conditions applied.

scopes is the operation's snapshot. Pass it whenever the operation runs more than one statement — a page and its count, a read and its includes — so both halves are scoped to the same tenant. Omitting it takes a fresh snapshot, which is correct only for a single-statement call.

Implementation

MssqlQuery baseQuery(
  MssqlScopeSelection selection, {
  MssqlScopeCompiler? scopes,
}) {
  var query = MssqlQuery.fromParts(
    binding.nameParts,
    ref: binding.sourceRef,
  ).select(binding.columns.map<MssqlExpression>((c) => Col(c.name)).toList());
  for (final condition
      in (scopes ?? scopeCompiler(selection)).readConditions) {
    query = query.where(condition);
  }
  return query;
}