kysely 0.23.4 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -25
- package/dist/cjs/dialect/database-introspector.d.ts +4 -2
- package/dist/cjs/dialect/mysql/mysql-adapter.js +2 -2
- package/dist/cjs/dialect/mysql/mysql-driver.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-driver.js +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +19 -13
- package/dist/cjs/dialect/postgres/postgres-adapter.js +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -1
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -0
- package/dist/cjs/dialect/sqlite/sqlite-dialect.js +1 -0
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +6 -5
- package/dist/cjs/driver/runtime-driver.js +4 -2
- package/dist/cjs/expression/expression-builder.d.ts +386 -0
- package/dist/cjs/expression/expression-builder.js +92 -0
- package/dist/cjs/expression/expression-wrapper.d.ts +92 -0
- package/dist/cjs/expression/expression-wrapper.js +54 -0
- package/dist/cjs/expression/expression.d.ts +1 -1
- package/dist/cjs/helpers/postgres.d.ts +133 -0
- package/dist/cjs/helpers/postgres.js +141 -0
- package/dist/cjs/index.d.ts +4 -3
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/kysely.d.ts +10 -0
- package/dist/cjs/kysely.js +12 -1
- package/dist/cjs/migration/file-migration-provider.d.ts +5 -2
- package/dist/cjs/migration/migrator.d.ts +5 -2
- package/dist/cjs/operation-node/aggregate-function-node.d.ts +3 -2
- package/dist/cjs/operation-node/aggregate-function-node.js +2 -2
- package/dist/cjs/operation-node/create-index-node.d.ts +2 -0
- package/dist/cjs/operation-node/delete-query-node.d.ts +1 -2
- package/dist/cjs/operation-node/delete-query-node.js +2 -8
- package/dist/cjs/operation-node/function-node.d.ts +13 -0
- package/dist/cjs/operation-node/function-node.js +19 -0
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +11 -2
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -0
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/operator-node.d.ts +13 -2
- package/dist/cjs/operation-node/operator-node.js +38 -3
- package/dist/cjs/operation-node/query-node.d.ts +25 -8
- package/dist/cjs/operation-node/query-node.js +9 -2
- package/dist/cjs/operation-node/select-query-node.d.ts +0 -1
- package/dist/cjs/operation-node/select-query-node.js +0 -6
- package/dist/cjs/operation-node/update-query-node.d.ts +0 -1
- package/dist/cjs/operation-node/update-query-node.js +0 -6
- package/dist/cjs/parser/binary-operation-parser.d.ts +9 -10
- package/dist/cjs/parser/binary-operation-parser.js +89 -39
- package/dist/cjs/parser/coalesce-parser.d.ts +0 -2
- package/dist/cjs/parser/coalesce-parser.js +0 -9
- package/dist/cjs/parser/expression-parser.d.ts +7 -3
- package/dist/cjs/parser/expression-parser.js +4 -4
- package/dist/cjs/parser/group-by-parser.d.ts +3 -2
- package/dist/cjs/parser/group-by-parser.js +3 -0
- package/dist/cjs/parser/insert-values-parser.d.ts +4 -1
- package/dist/cjs/parser/insert-values-parser.js +19 -13
- package/dist/cjs/parser/join-parser.js +1 -1
- package/dist/cjs/parser/parse-utils.d.ts +0 -2
- package/dist/cjs/parser/parse-utils.js +1 -8
- package/dist/cjs/parser/returning-parser.d.ts +2 -1
- package/dist/cjs/parser/select-parser.d.ts +5 -13
- package/dist/cjs/parser/select-parser.js +8 -4
- package/dist/cjs/parser/table-parser.d.ts +6 -3
- package/dist/cjs/parser/unary-operation-parser.d.ts +5 -2
- package/dist/cjs/parser/unary-operation-parser.js +9 -8
- package/dist/cjs/parser/update-set-parser.d.ts +4 -1
- package/dist/cjs/parser/update-set-parser.js +9 -4
- package/dist/cjs/parser/value-parser.d.ts +5 -0
- package/dist/cjs/parser/value-parser.js +1 -3
- package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +7 -0
- package/dist/cjs/plugin/camel-case/camel-case-plugin.js +10 -4
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +1 -1
- package/dist/cjs/plugin/deduplicate-joins/deduplicate-joins-plugin.js +1 -1
- package/dist/cjs/query-builder/aggregate-function-builder.d.ts +40 -113
- package/dist/cjs/query-builder/aggregate-function-builder.js +23 -63
- package/dist/cjs/query-builder/delete-query-builder.d.ts +224 -205
- package/dist/cjs/query-builder/delete-query-builder.js +21 -27
- package/dist/cjs/query-builder/delete-result.js +3 -0
- package/dist/cjs/query-builder/deprecated-having-expression-builder.d.ts +62 -0
- package/dist/cjs/query-builder/deprecated-having-expression-builder.js +2 -0
- package/dist/cjs/query-builder/deprecated-on-expression-builder.d.ts +62 -0
- package/dist/cjs/query-builder/deprecated-on-expression-builder.js +2 -0
- package/dist/cjs/query-builder/deprecated-where-expression-builder.d.ts +62 -0
- package/dist/cjs/query-builder/deprecated-where-expression-builder.js +2 -0
- package/dist/cjs/query-builder/function-module.d.ts +304 -42
- package/dist/cjs/query-builder/function-module.js +44 -208
- package/dist/cjs/query-builder/having-interface.d.ts +19 -16
- package/dist/cjs/query-builder/insert-query-builder.d.ts +78 -30
- package/dist/cjs/query-builder/insert-query-builder.js +21 -30
- package/dist/cjs/query-builder/insert-result.js +3 -0
- package/dist/cjs/query-builder/join-builder.d.ts +23 -26
- package/dist/cjs/query-builder/join-builder.js +17 -22
- package/dist/cjs/query-builder/no-result-error.d.ts +1 -0
- package/dist/cjs/query-builder/no-result-error.js +5 -1
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +158 -276
- package/dist/cjs/query-builder/on-conflict-builder.js +52 -36
- package/dist/cjs/query-builder/over-builder.d.ts +5 -0
- package/dist/cjs/query-builder/over-builder.js +7 -0
- package/dist/cjs/query-builder/returning-interface.d.ts +2 -2
- package/dist/cjs/query-builder/select-query-builder.d.ts +155 -243
- package/dist/cjs/query-builder/select-query-builder.js +333 -78
- package/dist/cjs/query-builder/update-query-builder.d.ts +149 -217
- package/dist/cjs/query-builder/update-query-builder.js +21 -115
- package/dist/cjs/query-builder/update-result.js +3 -0
- package/dist/cjs/query-builder/where-interface.d.ts +71 -184
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +3 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +18 -2
- package/dist/cjs/query-creator.d.ts +38 -2
- package/dist/cjs/query-creator.js +3 -45
- package/dist/cjs/query-executor/query-executor.d.ts +3 -3
- package/dist/cjs/raw-builder/raw-builder.d.ts +5 -3
- package/dist/cjs/raw-builder/raw-builder.js +13 -7
- package/dist/cjs/raw-builder/sql.d.ts +17 -9
- package/dist/cjs/raw-builder/sql.js +8 -2
- package/dist/cjs/schema/alter-column-builder.d.ts +5 -0
- package/dist/cjs/schema/alter-column-builder.js +7 -0
- package/dist/cjs/schema/alter-table-add-foreign-key-constraint-builder.d.ts +5 -0
- package/dist/cjs/schema/alter-table-add-foreign-key-constraint-builder.js +7 -0
- package/dist/cjs/schema/alter-table-drop-constraint-builder.d.ts +5 -0
- package/dist/cjs/schema/alter-table-drop-constraint-builder.js +7 -0
- package/dist/cjs/schema/column-definition-builder.d.ts +6 -1
- package/dist/cjs/schema/column-definition-builder.js +8 -1
- package/dist/cjs/schema/create-index-builder.d.ts +51 -9
- package/dist/cjs/schema/create-index-builder.js +17 -0
- package/dist/cjs/schema/create-schema-builder.d.ts +5 -0
- package/dist/cjs/schema/create-schema-builder.js +7 -0
- package/dist/cjs/schema/create-table-builder.d.ts +3 -1
- package/dist/cjs/schema/create-table-builder.js +3 -1
- package/dist/cjs/schema/create-type-builder.d.ts +5 -0
- package/dist/cjs/schema/create-type-builder.js +7 -0
- package/dist/cjs/schema/create-view-builder.d.ts +5 -0
- package/dist/cjs/schema/create-view-builder.js +7 -0
- package/dist/cjs/schema/drop-index-builder.d.ts +5 -0
- package/dist/cjs/schema/drop-index-builder.js +7 -0
- package/dist/cjs/schema/drop-schema-builder.d.ts +5 -0
- package/dist/cjs/schema/drop-schema-builder.js +7 -0
- package/dist/cjs/schema/drop-table-builder.d.ts +5 -0
- package/dist/cjs/schema/drop-table-builder.js +7 -0
- package/dist/cjs/schema/drop-type-builder.d.ts +5 -0
- package/dist/cjs/schema/drop-type-builder.js +7 -0
- package/dist/cjs/schema/drop-view-builder.d.ts +5 -0
- package/dist/cjs/schema/drop-view-builder.js +7 -0
- package/dist/cjs/schema/foreign-key-constraint-builder.d.ts +5 -0
- package/dist/cjs/schema/foreign-key-constraint-builder.js +7 -0
- package/dist/cjs/util/compilable.d.ts +1 -0
- package/dist/cjs/util/compilable.js +6 -0
- package/dist/cjs/util/explainable.d.ts +35 -0
- package/dist/cjs/util/log.d.ts +2 -0
- package/dist/cjs/util/object-utils.js +1 -1
- package/dist/cjs/util/streamable.d.ts +29 -0
- package/dist/cjs/util/streamable.js +2 -0
- package/dist/cjs/util/type-utils.d.ts +6 -4
- package/dist/esm/dialect/database-introspector.d.ts +4 -2
- package/dist/esm/dialect/mysql/mysql-adapter.js +2 -2
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-driver.js +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +19 -13
- package/dist/esm/dialect/postgres/postgres-adapter.js +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +3 -1
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -0
- package/dist/esm/dialect/sqlite/sqlite-dialect.js +1 -0
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +6 -5
- package/dist/esm/driver/runtime-driver.js +4 -2
- package/dist/esm/expression/expression-builder.d.ts +386 -0
- package/dist/esm/expression/expression-builder.js +88 -0
- package/dist/esm/expression/expression-wrapper.d.ts +92 -0
- package/dist/esm/expression/expression-wrapper.js +50 -0
- package/dist/esm/expression/expression.d.ts +1 -1
- package/dist/esm/helpers/postgres.d.ts +133 -0
- package/dist/esm/helpers/postgres.js +136 -0
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +2 -1
- package/dist/esm/kysely.d.ts +10 -0
- package/dist/esm/kysely.js +13 -2
- package/dist/esm/migration/file-migration-provider.d.ts +5 -2
- package/dist/esm/migration/migrator.d.ts +5 -2
- package/dist/esm/operation-node/aggregate-function-node.d.ts +3 -2
- package/dist/esm/operation-node/aggregate-function-node.js +2 -2
- package/dist/esm/operation-node/create-index-node.d.ts +2 -0
- package/dist/esm/operation-node/delete-query-node.d.ts +1 -2
- package/dist/esm/operation-node/delete-query-node.js +2 -8
- package/dist/esm/operation-node/function-node.d.ts +13 -0
- package/dist/esm/operation-node/function-node.js +17 -0
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-transformer.js +11 -2
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -0
- package/dist/esm/operation-node/operation-node-visitor.js +1 -0
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/operator-node.d.ts +13 -2
- package/dist/esm/operation-node/operator-node.js +34 -3
- package/dist/esm/operation-node/query-node.d.ts +25 -8
- package/dist/esm/operation-node/query-node.js +9 -2
- package/dist/esm/operation-node/select-query-node.d.ts +0 -1
- package/dist/esm/operation-node/select-query-node.js +0 -6
- package/dist/esm/operation-node/update-query-node.d.ts +0 -1
- package/dist/esm/operation-node/update-query-node.js +0 -6
- package/dist/esm/parser/binary-operation-parser.d.ts +9 -10
- package/dist/esm/parser/binary-operation-parser.js +85 -37
- package/dist/esm/parser/coalesce-parser.d.ts +0 -2
- package/dist/esm/parser/coalesce-parser.js +1 -7
- package/dist/esm/parser/expression-parser.d.ts +7 -3
- package/dist/esm/parser/expression-parser.js +5 -5
- package/dist/esm/parser/group-by-parser.d.ts +3 -2
- package/dist/esm/parser/group-by-parser.js +3 -0
- package/dist/esm/parser/insert-values-parser.d.ts +4 -1
- package/dist/esm/parser/insert-values-parser.js +18 -12
- package/dist/esm/parser/join-parser.js +2 -2
- package/dist/esm/parser/parse-utils.d.ts +0 -2
- package/dist/esm/parser/parse-utils.js +0 -6
- package/dist/esm/parser/returning-parser.d.ts +2 -1
- package/dist/esm/parser/select-parser.d.ts +5 -13
- package/dist/esm/parser/select-parser.js +7 -3
- package/dist/esm/parser/table-parser.d.ts +6 -3
- package/dist/esm/parser/unary-operation-parser.d.ts +5 -2
- package/dist/esm/parser/unary-operation-parser.js +8 -8
- package/dist/esm/parser/update-set-parser.d.ts +4 -1
- package/dist/esm/parser/update-set-parser.js +7 -2
- package/dist/esm/parser/value-parser.d.ts +5 -0
- package/dist/esm/parser/value-parser.js +1 -3
- package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +7 -0
- package/dist/esm/plugin/camel-case/camel-case-plugin.js +10 -4
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.d.ts +1 -1
- package/dist/esm/plugin/deduplicate-joins/deduplicate-joins-plugin.js +1 -1
- package/dist/esm/query-builder/aggregate-function-builder.d.ts +40 -113
- package/dist/esm/query-builder/aggregate-function-builder.js +24 -64
- package/dist/esm/query-builder/delete-query-builder.d.ts +224 -205
- package/dist/esm/query-builder/delete-query-builder.js +24 -30
- package/dist/esm/query-builder/delete-result.js +3 -0
- package/dist/esm/query-builder/deprecated-having-expression-builder.d.ts +62 -0
- package/dist/esm/query-builder/deprecated-having-expression-builder.js +2 -0
- package/dist/esm/query-builder/deprecated-on-expression-builder.d.ts +62 -0
- package/dist/esm/query-builder/deprecated-on-expression-builder.js +2 -0
- package/dist/esm/query-builder/deprecated-where-expression-builder.d.ts +62 -0
- package/dist/esm/query-builder/deprecated-where-expression-builder.js +2 -0
- package/dist/esm/query-builder/function-module.d.ts +304 -42
- package/dist/esm/query-builder/function-module.js +43 -207
- package/dist/esm/query-builder/having-interface.d.ts +19 -16
- package/dist/esm/query-builder/insert-query-builder.d.ts +78 -30
- package/dist/esm/query-builder/insert-query-builder.js +25 -34
- package/dist/esm/query-builder/insert-result.js +3 -0
- package/dist/esm/query-builder/join-builder.d.ts +23 -26
- package/dist/esm/query-builder/join-builder.js +18 -23
- package/dist/esm/query-builder/no-result-error.d.ts +1 -0
- package/dist/esm/query-builder/no-result-error.js +3 -0
- package/dist/esm/query-builder/on-conflict-builder.d.ts +158 -276
- package/dist/esm/query-builder/on-conflict-builder.js +54 -38
- package/dist/esm/query-builder/over-builder.d.ts +5 -0
- package/dist/esm/query-builder/over-builder.js +7 -0
- package/dist/esm/query-builder/returning-interface.d.ts +2 -2
- package/dist/esm/query-builder/select-query-builder.d.ts +155 -243
- package/dist/esm/query-builder/select-query-builder.js +337 -82
- package/dist/esm/query-builder/update-query-builder.d.ts +149 -217
- package/dist/esm/query-builder/update-query-builder.js +25 -119
- package/dist/esm/query-builder/update-result.js +3 -0
- package/dist/esm/query-builder/where-interface.d.ts +71 -184
- package/dist/esm/query-compiler/default-query-compiler.d.ts +3 -0
- package/dist/esm/query-compiler/default-query-compiler.js +18 -2
- package/dist/esm/query-creator.d.ts +38 -2
- package/dist/esm/query-creator.js +3 -45
- package/dist/esm/query-executor/query-executor.d.ts +3 -3
- package/dist/esm/raw-builder/raw-builder.d.ts +5 -3
- package/dist/esm/raw-builder/raw-builder.js +13 -7
- package/dist/esm/raw-builder/sql.d.ts +17 -9
- package/dist/esm/raw-builder/sql.js +8 -2
- package/dist/esm/schema/alter-column-builder.d.ts +5 -0
- package/dist/esm/schema/alter-column-builder.js +7 -0
- package/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.d.ts +5 -0
- package/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.js +7 -0
- package/dist/esm/schema/alter-table-drop-constraint-builder.d.ts +5 -0
- package/dist/esm/schema/alter-table-drop-constraint-builder.js +7 -0
- package/dist/esm/schema/column-definition-builder.d.ts +6 -1
- package/dist/esm/schema/column-definition-builder.js +8 -1
- package/dist/esm/schema/create-index-builder.d.ts +51 -9
- package/dist/esm/schema/create-index-builder.js +17 -0
- package/dist/esm/schema/create-schema-builder.d.ts +5 -0
- package/dist/esm/schema/create-schema-builder.js +7 -0
- package/dist/esm/schema/create-table-builder.d.ts +3 -1
- package/dist/esm/schema/create-table-builder.js +3 -1
- package/dist/esm/schema/create-type-builder.d.ts +5 -0
- package/dist/esm/schema/create-type-builder.js +7 -0
- package/dist/esm/schema/create-view-builder.d.ts +5 -0
- package/dist/esm/schema/create-view-builder.js +7 -0
- package/dist/esm/schema/drop-index-builder.d.ts +5 -0
- package/dist/esm/schema/drop-index-builder.js +7 -0
- package/dist/esm/schema/drop-schema-builder.d.ts +5 -0
- package/dist/esm/schema/drop-schema-builder.js +7 -0
- package/dist/esm/schema/drop-table-builder.d.ts +5 -0
- package/dist/esm/schema/drop-table-builder.js +7 -0
- package/dist/esm/schema/drop-type-builder.d.ts +5 -0
- package/dist/esm/schema/drop-type-builder.js +7 -0
- package/dist/esm/schema/drop-view-builder.d.ts +5 -0
- package/dist/esm/schema/drop-view-builder.js +7 -0
- package/dist/esm/schema/foreign-key-constraint-builder.d.ts +5 -0
- package/dist/esm/schema/foreign-key-constraint-builder.js +7 -0
- package/dist/esm/util/compilable.d.ts +1 -0
- package/dist/esm/util/compilable.js +4 -1
- package/dist/esm/util/explainable.d.ts +35 -0
- package/dist/esm/util/log.d.ts +2 -0
- package/dist/esm/util/object-utils.js +1 -1
- package/dist/esm/util/streamable.d.ts +29 -0
- package/dist/esm/util/streamable.js +2 -0
- package/dist/esm/util/type-utils.d.ts +6 -4
- package/helpers/postgres.d.ts +1 -0
- package/helpers/postgres.js +1 -0
- package/package.json +20 -9
- package/dist/cjs/query-builder/expression-builder.d.ts +0 -126
- package/dist/cjs/query-builder/expression-builder.js +0 -107
- package/dist/esm/query-builder/expression-builder.d.ts +0 -126
- package/dist/esm/query-builder/expression-builder.js +0 -104
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DynamicReferenceBuilder } from '../dynamic/dynamic-reference-builder.js';
|
|
2
|
+
import { ExpressionWrapper } from '../expression/expression-wrapper.js';
|
|
2
3
|
import { CoalesceReferenceExpressionList } from '../parser/coalesce-parser.js';
|
|
3
4
|
import { ExtractTypeFromReferenceExpression, SimpleReferenceExpression, ReferenceExpression, StringReference } from '../parser/reference-parser.js';
|
|
4
|
-
import { RawBuilder } from '../raw-builder/raw-builder.js';
|
|
5
5
|
import { Equals, IsNever } from '../util/type-utils.js';
|
|
6
6
|
import { AggregateFunctionBuilder } from './aggregate-function-builder.js';
|
|
7
7
|
/**
|
|
@@ -36,13 +36,70 @@ import { AggregateFunctionBuilder } from './aggregate-function-builder.js';
|
|
|
36
36
|
* having count("pet"."id") > $1
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export
|
|
40
|
-
|
|
39
|
+
export interface FunctionModule<DB, TB extends keyof DB> {
|
|
40
|
+
/**
|
|
41
|
+
* Creates a function call.
|
|
42
|
+
*
|
|
43
|
+
* ### Examples
|
|
44
|
+
*
|
|
45
|
+
* ```ts
|
|
46
|
+
* db.selectFrom('person')
|
|
47
|
+
* .selectAll('person')
|
|
48
|
+
* .where(db.fn('upper', ['first_name']), '=', 'JENNIFER')
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* The generated SQL (PostgreSQL):
|
|
52
|
+
*
|
|
53
|
+
* ```sql
|
|
54
|
+
* select "person".*
|
|
55
|
+
* from "person"
|
|
56
|
+
* where upper("first_name") = $1
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* If you prefer readability over type-safety, you can always use raw `sql`:
|
|
60
|
+
*
|
|
61
|
+
* ```ts
|
|
62
|
+
* db.selectFrom('person')
|
|
63
|
+
* .selectAll('person')
|
|
64
|
+
* .where(sql`upper(first_name)`, '=', 'JENNIFER')
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
<T>(name: string, args: ReadonlyArray<ReferenceExpression<DB, TB>>): ExpressionWrapper<T>;
|
|
41
68
|
/**
|
|
42
69
|
* Calls the `avg` function for the column given as the argument.
|
|
43
70
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
71
|
+
* This sql function calculates the average value for a given column.
|
|
72
|
+
*
|
|
73
|
+
* For additional functionality such as distinct, filtering and window functions,
|
|
74
|
+
* refer to {@link AggregateFunctionBuilder}. An instance of this builder is
|
|
75
|
+
* returned when calling this function.
|
|
76
|
+
*
|
|
77
|
+
* ### Examples
|
|
78
|
+
*
|
|
79
|
+
* ```ts
|
|
80
|
+
* const { avg } = db.fn
|
|
81
|
+
*
|
|
82
|
+
* db.selectFrom('toy')
|
|
83
|
+
* .select(avg('price').as('avg_price'))
|
|
84
|
+
* .execute()
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* The generated SQL (PostgreSQL):
|
|
88
|
+
*
|
|
89
|
+
* ```sql
|
|
90
|
+
* select avg("price") as "avg_price" from "toy"
|
|
91
|
+
* ```
|
|
92
|
+
*
|
|
93
|
+
* You can limit column range to only columns participating in current query:
|
|
94
|
+
*
|
|
95
|
+
* ```ts
|
|
96
|
+
* db.selectFrom('toy')
|
|
97
|
+
* .select((eb) => eb.fn.avg('price').as('avg_price'))
|
|
98
|
+
* .execute()
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* If this function is used in a `select` statement, the type of the selected
|
|
102
|
+
* expression will be `number | string` by default. This is because Kysely can't know the
|
|
46
103
|
* type the db driver outputs. Sometimes the output can be larger than the largest
|
|
47
104
|
* javascript number and a string is returned instead. Most drivers allow you
|
|
48
105
|
* to configure the output type of large numbers and Kysely can't know if you've
|
|
@@ -61,7 +118,7 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
|
|
|
61
118
|
*
|
|
62
119
|
* Sometimes a null is returned, e.g. when row count is 0, and no `group by`
|
|
63
120
|
* was used. It is highly recommended to include null in the output type union
|
|
64
|
-
* and handle null values in post-execute code, or wrap the function with a
|
|
121
|
+
* and handle null values in post-execute code, or wrap the function with a {@link coalesce}
|
|
65
122
|
* function.
|
|
66
123
|
*
|
|
67
124
|
* ```ts
|
|
@@ -76,42 +133,153 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
|
|
|
76
133
|
/**
|
|
77
134
|
* Calls the `coalesce` function for given arguments.
|
|
78
135
|
*
|
|
79
|
-
* This function returns the first non-null value from left to right, commonly
|
|
136
|
+
* This sql function returns the first non-null value from left to right, commonly
|
|
80
137
|
* used to provide a default scalar for nullable columns or functions.
|
|
81
138
|
*
|
|
139
|
+
* If this function is used in a `select` statement, the type of the selected
|
|
140
|
+
* expression is inferred in the same manner that the sql function computes.
|
|
141
|
+
* A union of arguments' types - if a non-nullable argument exists, it stops
|
|
142
|
+
* there (ignoring any further arguments' types) and exludes null from the final
|
|
143
|
+
* union type.
|
|
144
|
+
*
|
|
145
|
+
* `(string | null, number | null)` is inferred as `string | number | null`.
|
|
146
|
+
*
|
|
147
|
+
* `(string | null, number, Date | null)` is inferred as `string | number`.
|
|
148
|
+
*
|
|
149
|
+
* `(number, string | null)` is inferred as `number`.
|
|
150
|
+
*
|
|
151
|
+
* ### Examples
|
|
152
|
+
*
|
|
82
153
|
* ```ts
|
|
83
|
-
* const { coalesce
|
|
154
|
+
* const { coalesce } = db.fn
|
|
155
|
+
*
|
|
156
|
+
* db.selectFrom('participant')
|
|
157
|
+
* .select(coalesce('nickname', sql<string>`'<anonymous>'`).as('nickname'))
|
|
158
|
+
* .where('room_id', '=', roomId)
|
|
159
|
+
* .execute()
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* The generated SQL (PostgreSQL):
|
|
163
|
+
*
|
|
164
|
+
* ```sql
|
|
165
|
+
* select coalesce("nickname", '<anonymous>') as "nickname"
|
|
166
|
+
* from "participant" where "room_id" = $1
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* You can limit column range to only columns participating in current query:
|
|
170
|
+
*
|
|
171
|
+
* ```ts
|
|
172
|
+
* db.selectFrom('participant')
|
|
173
|
+
* .select((eb) =>
|
|
174
|
+
* eb.fn.coalesce('nickname', sql<string>`'<anonymous>'`).as('nickname')
|
|
175
|
+
* )
|
|
176
|
+
* .where('room_id', '=', roomId)
|
|
177
|
+
* .execute()
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* You can combine this function with other helpers in this module:
|
|
181
|
+
*
|
|
182
|
+
* ```ts
|
|
183
|
+
* const { avg, coalesce } = db.fn
|
|
84
184
|
*
|
|
85
185
|
* db.selectFrom('person')
|
|
86
|
-
* .select(coalesce(
|
|
186
|
+
* .select(coalesce(avg<number | null>('age'), sql<number>`0`).as('avg_age'))
|
|
87
187
|
* .where('first_name', '=', 'Jennifer')
|
|
88
188
|
* .execute()
|
|
89
189
|
* ```
|
|
90
190
|
*
|
|
91
|
-
* The generated SQL (
|
|
191
|
+
* The generated SQL (PostgreSQL):
|
|
92
192
|
*
|
|
93
193
|
* ```sql
|
|
94
|
-
* select coalesce(
|
|
194
|
+
* select coalesce(avg("age"), 0) as "avg_age" from "person" where "first_name" = $1
|
|
95
195
|
* ```
|
|
196
|
+
*/
|
|
197
|
+
coalesce<V extends ReferenceExpression<DB, TB>, OV extends ReferenceExpression<DB, TB>[]>(value: V, ...otherValues: OV): ExpressionWrapper<CoalesceReferenceExpressionList<DB, TB, [V, ...OV]>>;
|
|
198
|
+
/**
|
|
199
|
+
* Calls the `count` function for the column given as the argument.
|
|
96
200
|
*
|
|
97
|
-
*
|
|
98
|
-
* is
|
|
99
|
-
* types - if a non-nullable argument exists, it stops there (ignoring any further
|
|
100
|
-
* arguments' types) and exludes null from the final union type.
|
|
201
|
+
* When called with a column as argument, this sql function counts the number of rows where there
|
|
202
|
+
* is a non-null value in that column.
|
|
101
203
|
*
|
|
102
|
-
*
|
|
204
|
+
* For counting all rows nulls included (`count(*)`), see {@link countAll}.
|
|
103
205
|
*
|
|
104
|
-
*
|
|
206
|
+
* For additional functionality such as distinct, filtering and window functions,
|
|
207
|
+
* refer to {@link AggregateFunctionBuilder}. An instance of this builder is
|
|
208
|
+
* returned when calling this function.
|
|
105
209
|
*
|
|
106
|
-
*
|
|
210
|
+
* ### Examples
|
|
107
211
|
*
|
|
108
|
-
*
|
|
212
|
+
* ```ts
|
|
213
|
+
* const { count } = db.fn
|
|
214
|
+
*
|
|
215
|
+
* db.selectFrom('toy')
|
|
216
|
+
* .select(count('id').as('num_toys'))
|
|
217
|
+
* .execute()
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* The generated SQL (PostgreSQL):
|
|
221
|
+
*
|
|
222
|
+
* ```sql
|
|
223
|
+
* select count("id") as "num_toys" from "toy"
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* If this function is used in a `select` statement, the type of the selected
|
|
227
|
+
* expression will be `number | string | bigint` by default. This is because
|
|
228
|
+
* Kysely can't know the type the db driver outputs. Sometimes the output can
|
|
229
|
+
* be larger than the largest javascript number and a string is returned instead.
|
|
230
|
+
* Most drivers allow you to configure the output type of large numbers and Kysely
|
|
231
|
+
* can't know if you've done so.
|
|
232
|
+
*
|
|
233
|
+
* You can specify the output type of the expression by providing
|
|
234
|
+
* the type as the first type argument:
|
|
235
|
+
*
|
|
236
|
+
* ```ts
|
|
237
|
+
* const { count } = db.fn
|
|
238
|
+
*
|
|
239
|
+
* db.selectFrom('toy')
|
|
240
|
+
* .select(count<number>('id').as('num_toys'))
|
|
241
|
+
* .execute()
|
|
242
|
+
* ```
|
|
243
|
+
*
|
|
244
|
+
* You can limit column range to only columns participating in current query:
|
|
245
|
+
*
|
|
246
|
+
* ```ts
|
|
247
|
+
* db.selectFrom('toy')
|
|
248
|
+
* .select((eb) => eb.fn.count('id').as('num_toys'))
|
|
249
|
+
* .execute()
|
|
250
|
+
* ```
|
|
109
251
|
*/
|
|
110
|
-
|
|
252
|
+
count<O extends number | string | bigint, C extends SimpleReferenceExpression<DB, TB> = SimpleReferenceExpression<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, O>;
|
|
111
253
|
/**
|
|
112
|
-
* Calls the `count` function
|
|
254
|
+
* Calls the `count` function with `*` or `table.*` as argument.
|
|
255
|
+
*
|
|
256
|
+
* When called with `*` as argument, this sql function counts the number of rows,
|
|
257
|
+
* nulls included.
|
|
258
|
+
*
|
|
259
|
+
* For counting rows with non-null values in a given column (`count(column)`),
|
|
260
|
+
* see {@link count}.
|
|
261
|
+
*
|
|
262
|
+
* For additional functionality such as filtering and window functions, refer
|
|
263
|
+
* to {@link AggregateFunctionBuilder}. An instance of this builder is returned
|
|
264
|
+
* when calling this function.
|
|
265
|
+
*
|
|
266
|
+
* ### Examples
|
|
267
|
+
*
|
|
268
|
+
* ```ts
|
|
269
|
+
* const { countAll } = db.fn
|
|
270
|
+
*
|
|
271
|
+
* db.selectFrom('toy')
|
|
272
|
+
* .select(countAll().as('num_toys'))
|
|
273
|
+
* .execute()
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* The generated SQL (PostgreSQL):
|
|
113
277
|
*
|
|
114
|
-
*
|
|
278
|
+
* ```sql
|
|
279
|
+
* select count(*) as "num_toys" from "toy"
|
|
280
|
+
* ```
|
|
281
|
+
*
|
|
282
|
+
* If this is used in a `select` statement, the type of the selected expression
|
|
115
283
|
* will be `number | string | bigint` by default. This is because Kysely
|
|
116
284
|
* can't know the type the db driver outputs. Sometimes the output can be larger
|
|
117
285
|
* than the largest javascript number and a string is returned instead. Most
|
|
@@ -122,27 +290,55 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
|
|
|
122
290
|
* the type as the first type argument:
|
|
123
291
|
*
|
|
124
292
|
* ```ts
|
|
125
|
-
* const {
|
|
293
|
+
* const { countAll } = db.fn
|
|
126
294
|
*
|
|
127
295
|
* db.selectFrom('toy')
|
|
128
|
-
* .select(
|
|
296
|
+
* .select(countAll<number>().as('num_toys'))
|
|
129
297
|
* .execute()
|
|
130
298
|
* ```
|
|
131
299
|
*
|
|
132
|
-
*
|
|
300
|
+
* Some databases, such as PostgreSQL, support scoping the function to a specific
|
|
301
|
+
* table:
|
|
133
302
|
*
|
|
134
303
|
* ```ts
|
|
304
|
+
* const { countAll } = db.fn
|
|
305
|
+
*
|
|
135
306
|
* db.selectFrom('toy')
|
|
136
|
-
* .
|
|
307
|
+
* .innerJoin('pet', 'pet.id', 'toy.pet_id')
|
|
308
|
+
* .select(countAll('toy').as('num_toys'))
|
|
309
|
+
* .execute()
|
|
310
|
+
* ```
|
|
311
|
+
*
|
|
312
|
+
* The generated SQL (PostgreSQL):
|
|
313
|
+
*
|
|
314
|
+
* ```sql
|
|
315
|
+
* select count("toy".*) as "num_toys"
|
|
316
|
+
* from "toy" inner join "pet" on "pet"."id" = "toy"."pet_id"
|
|
317
|
+
* ```
|
|
318
|
+
*
|
|
319
|
+
* You can limit table range to only tables participating in current query:
|
|
320
|
+
*
|
|
321
|
+
* ```ts
|
|
322
|
+
* db.selectFrom('toy')
|
|
323
|
+
* .innerJoin('pet', 'pet.id', 'toy.pet_id')
|
|
324
|
+
* .select((eb) => eb.fn.countAll('toy').as('num_toys'))
|
|
137
325
|
* .execute()
|
|
138
326
|
* ```
|
|
139
327
|
*/
|
|
140
|
-
|
|
328
|
+
countAll<O extends number | string | bigint, T extends TB = TB>(table: T): AggregateFunctionBuilder<DB, TB, O>;
|
|
329
|
+
countAll<O extends number | string | bigint>(): AggregateFunctionBuilder<DB, TB, O>;
|
|
141
330
|
/**
|
|
142
331
|
* Calls the `max` function for the column given as the argument.
|
|
143
332
|
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
333
|
+
* This sql function calculates the maximum value for a given column.
|
|
334
|
+
*
|
|
335
|
+
* For additional functionality such as distinct, filtering and window functions,
|
|
336
|
+
* refer to {@link AggregateFunctionBuilder}. An instance of this builder is
|
|
337
|
+
* returned when calling this function.
|
|
338
|
+
*
|
|
339
|
+
* If this function is used in a `select` statement, the type of the selected
|
|
340
|
+
* expression will be the referenced column's type. This is because the result
|
|
341
|
+
* is within the column's value range.
|
|
146
342
|
*
|
|
147
343
|
* ### Examples
|
|
148
344
|
*
|
|
@@ -154,9 +350,23 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
|
|
|
154
350
|
* .execute()
|
|
155
351
|
* ```
|
|
156
352
|
*
|
|
353
|
+
* The generated SQL (PostgreSQL):
|
|
354
|
+
*
|
|
355
|
+
* ```sql
|
|
356
|
+
* select max("price") as "max_price" from "toy"
|
|
357
|
+
* ```
|
|
358
|
+
*
|
|
359
|
+
* You can limit column range to only columns participating in current query:
|
|
360
|
+
*
|
|
361
|
+
* ```ts
|
|
362
|
+
* db.selectFrom('toy')
|
|
363
|
+
* .select((eb) => eb.fn.max('price').as('max_price'))
|
|
364
|
+
* .execute()
|
|
365
|
+
* ```
|
|
366
|
+
*
|
|
157
367
|
* Sometimes a null is returned, e.g. when row count is 0, and no `group by`
|
|
158
368
|
* was used. It is highly recommended to include null in the output type union
|
|
159
|
-
* and handle null values in post-execute code, or wrap the function with a
|
|
369
|
+
* and handle null values in post-execute code, or wrap the function with a {@link coalesce}
|
|
160
370
|
* function.
|
|
161
371
|
*
|
|
162
372
|
* ```ts
|
|
@@ -172,8 +382,15 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
|
|
|
172
382
|
/**
|
|
173
383
|
* Calls the `min` function for the column given as the argument.
|
|
174
384
|
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
385
|
+
* This sql function calculates the minimum value for a given column.
|
|
386
|
+
*
|
|
387
|
+
* For additional functionality such as distinct, filtering and window functions,
|
|
388
|
+
* refer to {@link AggregateFunctionBuilder}. An instance of this builder is
|
|
389
|
+
* returned when calling this function.
|
|
390
|
+
*
|
|
391
|
+
* If this function is used in a `select` statement, the type of the selected
|
|
392
|
+
* expression will be the referenced column's type. This is because the result
|
|
393
|
+
* is within the column's value range.
|
|
177
394
|
*
|
|
178
395
|
* ### Examples
|
|
179
396
|
*
|
|
@@ -185,9 +402,23 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
|
|
|
185
402
|
* .execute()
|
|
186
403
|
* ```
|
|
187
404
|
*
|
|
405
|
+
* The generated SQL (PostgreSQL):
|
|
406
|
+
*
|
|
407
|
+
* ```sql
|
|
408
|
+
* select min("price") as "min_price" from "toy"
|
|
409
|
+
* ```
|
|
410
|
+
*
|
|
411
|
+
* You can limit column range to only columns participating in current query:
|
|
412
|
+
*
|
|
413
|
+
* ```ts
|
|
414
|
+
* db.selectFrom('toy')
|
|
415
|
+
* .select((eb) => eb.fn.min('price').as('min_price'))
|
|
416
|
+
* .execute()
|
|
417
|
+
* ```
|
|
418
|
+
*
|
|
188
419
|
* Sometimes a null is returned, e.g. when row count is 0, and no `group by`
|
|
189
420
|
* was used. It is highly recommended to include null in the output type union
|
|
190
|
-
* and handle null values in post-execute code, or wrap the function with a
|
|
421
|
+
* and handle null values in post-execute code, or wrap the function with a {@link coalesce}
|
|
191
422
|
* function.
|
|
192
423
|
*
|
|
193
424
|
* ```ts
|
|
@@ -203,15 +434,45 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
|
|
|
203
434
|
/**
|
|
204
435
|
* Calls the `sum` function for the column given as the argument.
|
|
205
436
|
*
|
|
206
|
-
*
|
|
207
|
-
* will be `number | string | bigint` by default. This is because Kysely
|
|
208
|
-
* can't know the type the db driver outputs. Sometimes the output can be larger
|
|
209
|
-
* than the largest javascript number and a string is returned instead. Most
|
|
210
|
-
* drivers allow you to configure the output type of large numbers and Kysely
|
|
211
|
-
* can't know if you've done so.
|
|
437
|
+
* This sql function sums the values of a given column.
|
|
212
438
|
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
439
|
+
* For additional functionality such as distinct, filtering and window functions,
|
|
440
|
+
* refer to {@link AggregateFunctionBuilder}. An instance of this builder is
|
|
441
|
+
* returned when calling this function.
|
|
442
|
+
*
|
|
443
|
+
* ### Examples
|
|
444
|
+
*
|
|
445
|
+
* ```ts
|
|
446
|
+
* const { sum } = db.fn
|
|
447
|
+
*
|
|
448
|
+
* db.selectFrom('toy')
|
|
449
|
+
* .select(sum('price').as('total_price'))
|
|
450
|
+
* .execute()
|
|
451
|
+
* ```
|
|
452
|
+
*
|
|
453
|
+
* The generated SQL (PostgreSQL):
|
|
454
|
+
*
|
|
455
|
+
* ```sql
|
|
456
|
+
* select sum("price") as "total_price" from "toy"
|
|
457
|
+
* ```
|
|
458
|
+
*
|
|
459
|
+
* You can limit column range to only columns participating in current query:
|
|
460
|
+
*
|
|
461
|
+
* ```ts
|
|
462
|
+
* db.selectFrom('toy')
|
|
463
|
+
* .select((eb) => eb.fn.sum('price').as('total_price'))
|
|
464
|
+
* .execute()
|
|
465
|
+
* ```
|
|
466
|
+
*
|
|
467
|
+
* If this function is used in a `select` statement, the type of the selected
|
|
468
|
+
* expression will be `number | string` by default. This is because Kysely can't know the
|
|
469
|
+
* type the db driver outputs. Sometimes the output can be larger than the largest
|
|
470
|
+
* javascript number and a string is returned instead. Most drivers allow you
|
|
471
|
+
* to configure the output type of large numbers and Kysely can't know if you've
|
|
472
|
+
* done so.
|
|
473
|
+
*
|
|
474
|
+
* You can specify the output type of the expression by providing the type as
|
|
475
|
+
* the first type argument:
|
|
215
476
|
*
|
|
216
477
|
* ```ts
|
|
217
478
|
* const { sum } = db.fn
|
|
@@ -223,7 +484,7 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
|
|
|
223
484
|
*
|
|
224
485
|
* Sometimes a null is returned, e.g. when row count is 0, and no `group by`
|
|
225
486
|
* was used. It is highly recommended to include null in the output type union
|
|
226
|
-
* and handle null values in post-execute code, or wrap the function with a
|
|
487
|
+
* and handle null values in post-execute code, or wrap the function with a {@link coalesce}
|
|
227
488
|
* function.
|
|
228
489
|
*
|
|
229
490
|
* ```ts
|
|
@@ -236,6 +497,7 @@ export declare class FunctionModule<DB, TB extends keyof DB> {
|
|
|
236
497
|
*/
|
|
237
498
|
sum<O extends number | string | bigint | null = number | string | bigint, C extends SimpleReferenceExpression<DB, TB> = SimpleReferenceExpression<DB, TB>>(column: C): AggregateFunctionBuilder<DB, TB, O>;
|
|
238
499
|
}
|
|
500
|
+
export declare function createFunctionModule<DB, TB extends keyof DB>(): FunctionModule<DB, TB>;
|
|
239
501
|
declare type OutputBoundStringReference<DB, TB extends keyof DB, C extends StringReference<DB, TB>, O> = IsNever<O> extends true ? C : Equals<ExtractTypeFromReferenceExpression<DB, TB, C> | null, O | null> extends true ? C : never;
|
|
240
502
|
declare type StringReferenceBoundAggregateFunctionBuilder<DB, TB extends keyof DB, C extends StringReference<DB, TB>, O> = AggregateFunctionBuilder<DB, TB, ExtractTypeFromReferenceExpression<DB, TB, C> | (null extends O ? null : never)>;
|
|
241
503
|
export {};
|