AggregateFunctionBuilder
AggregateFunctionBuilder is returned by aggregate function calls from the FunctionModule. It provides methods for adding modifiers like distinct, filter, order by, and over clauses to aggregate functions.
Type Parameters
object
required
The database schema type
keyof DB
required
The table references available in the current query context
any
default:"unknown"
The output type of the aggregate function
Methods
as
Returns an aliased version of the function.string
required
The alias name for the aggregate function result
as "the_alias" to the end of the SQL, this method also provides strict typing.
Example:
distinct
Adds adistinct clause inside the function.
orderBy
Adds anorder by clause inside the aggregate function.
OrderByExpression
required
Column or expression to order by
OrderByModifiers
Optional order modifiers (e.g.,
asc, desc, nulls handling)clearOrderBy
Removes all order by clauses from the aggregate function.withinGroupOrderBy
Adds awithin group clause with a nested order by clause after the function.
OrderByExpression
required
Column or expression to order by
OrderByModifiers
Optional order modifiers
filterWhere
Adds afilter clause with a nested where clause after the function.
ReferenceExpression
required
Left-hand side column reference
ComparisonOperatorExpression
required
Comparison operator
OperandValueExpressionOrList
required
Right-hand side value or expression
ExpressionOrFactory
Alternative: full expression or factory function
filterWhereRef
Adds afilter clause with a nested where clause after the function, where both sides of the operator are references to columns.
ReferenceExpression
required
Left-hand side column reference
ComparisonOperatorExpression
required
Comparison operator
ReferenceExpression
required
Right-hand side column reference
over
Adds anover clause (window functions) after the function.
OverBuilderCallback
Optional callback that returns an OverBuilder with partition by and order by clauses
$call
Simply calls the provided function passingthis as the only argument. $call returns what the provided function returns.
function
required
Function to call with this builder as argument
$castTo
Casts the expression to the given type.type parameter
required
The new output type
AggregateFunctionBuilder with a new output type.
$notNull
Omit null from the expression’s type.this with a new output type.
toOperationNode
Converts the builder to an operation node for internal use.Related Types
AliasedAggregateFunctionBuilder
AggregateFunctionBuilder with an alias. The result of calling AggregateFunctionBuilder.as.
object
required
The database schema type
keyof DB
required
The table references
any
The output type
string
The alias name
OverBuilderCallback
Callback type for theover method.