scalar method

Expr<R?> scalar()

Converts a scalar selection into a nullable SQL subquery.

Requires take(1) or an ungrouped aggregate. This builds an expression and does not execute the subquery independently.

Implementation

Expr<R?> scalar() {
  final selection = querySelection;
  if (selection is! Expr<R>) {
    throw const OrmException(
      'QUERY.SCALAR',
      'A scalar subquery selects one SQL expression.',
    );
  }
  if (queryState.limit != 1 &&
      !(queryState.group.isEmpty && aggregate(selection.expressionNode))) {
    throw const OrmException(
      'QUERY.SCALAR',
      'Use take(1) or an ungrouped aggregate for a scalar subquery.',
    );
  }
  return Expr.internal(SubqueryNode(this), selection.codec.nullable());
}