/opt/canhelp/node_modules/kysely/dist/esm/query-builder
NameSizeModeActions
aggregate-function-builder.d.ts136020644editdlrm
aggregate-function-builder.js76660644editdlrm
case-builder.d.ts66890644editdlrm
case-builder.js25630644editdlrm
cte-builder.d.ts8020644editdlrm
cte-builder.js9610644editdlrm
delete-query-builder.d.ts474430644editdlrm
delete-query-builder.js158430644editdlrm
delete-result.d.ts1160644editdlrm
delete-result.js1830644editdlrm
function-module.d.ts235210644editdlrm
function-module.js22990644editdlrm
having-interface.d.ts9530644editdlrm
having-interface.js610644editdlrm
insert-query-builder.d.ts402150644editdlrm
insert-query-builder.js357260644editdlrm
insert-result.d.ts17350644editdlrm
insert-result.js17830644editdlrm
join-builder.d.ts17730644editdlrm
join-builder.js15830644editdlrm
json-path-builder.d.ts95450644editdlrm
json-path-builder.js58170644editdlrm
merge-query-builder.d.ts370250644editdlrm
merge-query-builder.js200650644editdlrm
merge-result.d.ts1390644editdlrm
merge-result.js1810644editdlrm
no-result-error.d.ts4780644editdlrm
no-result-error.js3840644editdlrm
on-conflict-builder.d.ts255730644editdlrm
on-conflict-builder.js81160644editdlrm
order-by-interface.d.ts48830644editdlrm
order-by-interface.js630644editdlrm
order-by-item-builder.d.ts13720644editdlrm
order-by-item-builder.js21320644editdlrm
output-interface.d.ts54770644editdlrm
output-interface.js610644editdlrm
over-builder.d.ts37550644editdlrm
over-builder.js12390644editdlrm
returning-interface.d.ts34960644editdlrm
returning-interface.js640644editdlrm
select-query-builder-expression.d.ts9620644editdlrm
select-query-builder-expression.js760644editdlrm
select-query-builder.d.ts784670644editdlrm
select-query-builder.js130620644editdlrm
update-query-builder.d.ts502540644editdlrm
update-query-builder.js164410644editdlrm
update-result.d.ts4970644editdlrm
update-result.js5720644editdlrm
where-interface.d.ts108140644editdlrm
where-interface.js600644editdlrm
Edit: /opt/canhelp/node_modules/kysely/dist/esm/query-builder/aggregate-function-builder.js (7666B)
/// import { freeze } from '../util/object-utils.js'; import { AggregateFunctionNode } from '../operation-node/aggregate-function-node.js'; import { AliasNode } from '../operation-node/alias-node.js'; import { IdentifierNode } from '../operation-node/identifier-node.js'; import { createOverBuilder } from '../parser/parse-utils.js'; import { parseReferentialBinaryOperation, parseValueBinaryOperationOrExpression, } from '../parser/binary-operation-parser.js'; import { parseOrderBy, } from '../parser/order-by-parser.js'; import { QueryNode } from '../operation-node/query-node.js'; export class AggregateFunctionBuilder { #props; constructor(props) { this.#props = freeze(props); } /** @private */ get expressionType() { return undefined; } /** * Returns an aliased version of the function. * * In addition to slapping `as "the_alias"` to the end of the SQL, * this method also provides strict typing: * * ```ts * const result = await db * .selectFrom('person') * .select( * (eb) => eb.fn.count('id').as('person_count') * ) * .executeTakeFirstOrThrow() * * // `person_count: number` field exists in the result type. * console.log(result.person_count) * ``` * * The generated SQL (PostgreSQL): * * ```sql * select count("id") as "person_count" * from "person" * ``` */ as(alias) { return new AliasedAggregateFunctionBuilder(this, alias); } /** * Adds a `distinct` clause inside the function. * * ### Examples * * ```ts * const result = await db * .selectFrom('person') * .select((eb) => * eb.fn.count('first_name').distinct().as('first_name_count') * ) * .executeTakeFirstOrThrow() * ``` * * The generated SQL (PostgreSQL): * * ```sql * select count(distinct "first_name") as "first_name_count" * from "person" * ``` */ distinct() { return new AggregateFunctionBuilder({ ...this.#props, aggregateFunctionNode: AggregateFunctionNode.cloneWithDistinct(this.#props.aggregateFunctionNode), }); } orderBy(...args) { return new AggregateFunctionBuilder({ ...this.#props, aggregateFunctionNode: QueryNode.cloneWithOrderByItems(this.#props.aggregateFunctionNode, parseOrderBy(args)), }); } clearOrderBy() { return new AggregateFunctionBuilder({ ...this.#props, aggregateFunctionNode: QueryNode.cloneWithoutOrderBy(this.#props.aggregateFunctionNode), }); } withinGroupOrderBy(...args) { return new AggregateFunctionBuilder({ ...this.#props, aggregateFunctionNode: AggregateFunctionNode.cloneWithOrderBy(this.#props.aggregateFunctionNode, parseOrderBy(args), true), }); } filterWhere(...args) { return new AggregateFunctionBuilder({ ...this.#props, aggregateFunctionNode: AggregateFunctionNode.cloneWithFilter(this.#props.aggregateFunctionNode, parseValueBinaryOperationOrExpression(args)), }); } /** * Adds a `filter` clause with a nested `where` clause after the function, where * both sides of the operator are references to columns. * * Similar to {@link WhereInterface}'s `whereRef` method. * * ### Examples * * Count people with same first and last names versus general public: * * ```ts * const result = await db * .selectFrom('person') * .select((eb) => [ * eb.fn * .count('id') * .filterWhereRef('first_name', '=', 'last_name') * .as('repeat_name_count'), * eb.fn.count('id').as('total_count'), * ]) * .executeTakeFirstOrThrow() * ``` * * The generated SQL (PostgreSQL): * * ```sql * select * count("id") filter(where "first_name" = "last_name") as "repeat_name_count", * count("id") as "total_count" * from "person" * ``` */ filterWhereRef(lhs, op, rhs) { return new AggregateFunctionBuilder({ ...this.#props, aggregateFunctionNode: AggregateFunctionNode.cloneWithFilter(this.#props.aggregateFunctionNode, parseReferentialBinaryOperation(lhs, op, rhs)), }); } /** * Adds an `over` clause (window functions) after the function. * * ### Examples * * ```ts * const result = await db * .selectFrom('person') * .select( * (eb) => eb.fn.avg('age').over().as('average_age') * ) * .execute() * ``` * * The generated SQL (PostgreSQL): * * ```sql * select avg("age") over() as "average_age" * from "person" * ``` * * Also supports passing a callback that returns an over builder, * allowing to add partition by and sort by clauses inside over. * * ```ts * const result = await db * .selectFrom('person') * .select( * (eb) => eb.fn.avg('age').over( * ob => ob.partitionBy('last_name').orderBy('first_name', 'asc') * ).as('average_age') * ) * .execute() * ``` * * The generated SQL (PostgreSQL): * * ```sql * select avg("age") over(partition by "last_name" order by "first_name" asc) as "average_age" * from "person" * ``` */ over(over) { const builder = createOverBuilder(); return new AggregateFunctionBuilder({ ...this.#props, aggregateFunctionNode: AggregateFunctionNode.cloneWithOver(this.#props.aggregateFunctionNode, (over ? over(builder) : builder).toOperationNode()), }); } /** * Simply calls the provided function passing `this` as the only argument. `$call` returns * what the provided function returns. */ $call(func) { return func(this); } /** * Casts the expression to the given type. * * This method call doesn't change the SQL in any way. This methods simply * returns a copy of this `AggregateFunctionBuilder` with a new output type. */ $castTo() { return new AggregateFunctionBuilder(this.#props); } /** * Omit null from the expression's type. * * This function can be useful in cases where you know an expression can't be * null, but Kysely is unable to infer it. * * This method call doesn't change the SQL in any way. This methods simply * returns a copy of `this` with a new output type. */ $notNull() { return new AggregateFunctionBuilder(this.#props); } toOperationNode() { return this.#props.aggregateFunctionNode; } } /** * {@link AggregateFunctionBuilder} with an alias. The result of calling {@link AggregateFunctionBuilder.as}. */ export class AliasedAggregateFunctionBuilder { #aggregateFunctionBuilder; #alias; constructor(aggregateFunctionBuilder, alias) { this.#aggregateFunctionBuilder = aggregateFunctionBuilder; this.#alias = alias; } /** @private */ get expression() { return this.#aggregateFunctionBuilder; } /** @private */ get alias() { return this.#alias; } toOperationNode() { return AliasNode.create(this.#aggregateFunctionBuilder.toOperationNode(), IdentifierNode.create(this.#alias)); } }