bind method

Query<R, F> bind(
  1. QueryContext db,
  2. Map<String, Expr<Object?>> arguments
)

Creates a query bound to db, without executing its SQL source.

The context selects its engine's template. Further filters and projections operate on the declared result columns; generated bindings normally supply the typed argument map. No fallback to another engine's SQL is attempted.

Implementation

Query<R, F> bind(QueryContext db, Map<String, Expr<Object?>> arguments) {
  final template = sql[db.dialect];
  if (template == null) {
    throw const OrmException(
      'QUERY.DIALECT',
      'No SQL source was declared for this backend.',
    );
  }
  final fields = result.createFields(TableRef(result.schema));
  return Query.internal(
    db,
    fields,
    QueryState(
      fields.table,
      ctes: [
        _SqlCte(result.schema.name, template, Map.unmodifiable(arguments)),
      ],
    ),
    result.selectRow(fields),
  );
}