/
opt
/
canhelp
/
node_modules
/
kysely
/
dist
/
esm
/
query-builder
/
/opt/canhelp/node_modules/kysely/dist/esm/query-builder
mkdir
upload
Name
Size
Mode
Actions
aggregate-function-builder.d.ts
13602
0644
edit
dl
rm
aggregate-function-builder.js
7666
0644
edit
dl
rm
case-builder.d.ts
6689
0644
edit
dl
rm
case-builder.js
2563
0644
edit
dl
rm
cte-builder.d.ts
802
0644
edit
dl
rm
cte-builder.js
961
0644
edit
dl
rm
delete-query-builder.d.ts
47443
0644
edit
dl
rm
delete-query-builder.js
15843
0644
edit
dl
rm
delete-result.d.ts
116
0644
edit
dl
rm
delete-result.js
183
0644
edit
dl
rm
function-module.d.ts
23521
0644
edit
dl
rm
function-module.js
2299
0644
edit
dl
rm
having-interface.d.ts
953
0644
edit
dl
rm
having-interface.js
61
0644
edit
dl
rm
insert-query-builder.d.ts
40215
0644
edit
dl
rm
insert-query-builder.js
35726
0644
edit
dl
rm
insert-result.d.ts
1735
0644
edit
dl
rm
insert-result.js
1783
0644
edit
dl
rm
join-builder.d.ts
1773
0644
edit
dl
rm
join-builder.js
1583
0644
edit
dl
rm
json-path-builder.d.ts
9545
0644
edit
dl
rm
json-path-builder.js
5817
0644
edit
dl
rm
merge-query-builder.d.ts
37025
0644
edit
dl
rm
merge-query-builder.js
20065
0644
edit
dl
rm
merge-result.d.ts
139
0644
edit
dl
rm
merge-result.js
181
0644
edit
dl
rm
no-result-error.d.ts
478
0644
edit
dl
rm
no-result-error.js
384
0644
edit
dl
rm
on-conflict-builder.d.ts
25573
0644
edit
dl
rm
on-conflict-builder.js
8116
0644
edit
dl
rm
order-by-interface.d.ts
4883
0644
edit
dl
rm
order-by-interface.js
63
0644
edit
dl
rm
order-by-item-builder.d.ts
1372
0644
edit
dl
rm
order-by-item-builder.js
2132
0644
edit
dl
rm
output-interface.d.ts
5477
0644
edit
dl
rm
output-interface.js
61
0644
edit
dl
rm
over-builder.d.ts
3755
0644
edit
dl
rm
over-builder.js
1239
0644
edit
dl
rm
returning-interface.d.ts
3496
0644
edit
dl
rm
returning-interface.js
64
0644
edit
dl
rm
select-query-builder-expression.d.ts
962
0644
edit
dl
rm
select-query-builder-expression.js
76
0644
edit
dl
rm
select-query-builder.d.ts
78467
0644
edit
dl
rm
select-query-builder.js
13062
0644
edit
dl
rm
update-query-builder.d.ts
50254
0644
edit
dl
rm
update-query-builder.js
16441
0644
edit
dl
rm
update-result.d.ts
497
0644
edit
dl
rm
update-result.js
572
0644
edit
dl
rm
where-interface.d.ts
10814
0644
edit
dl
rm
where-interface.js
60
0644
edit
dl
rm
Edit:
/opt/canhelp/node_modules/kysely/dist/esm/query-builder/aggregate-function-builder.js
(7666B)
/// <reference types="./aggregate-function-builder.d.ts" /> 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<number>('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<number>('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<number>('id') * .filterWhereRef('first_name', '=', 'last_name') * .as('repeat_name_count'), * eb.fn.count<number>('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<number>('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<number>('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)); } }
Save
cmd:
run