kysely 0.16.9 → 0.17.1
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/LICENSE +21 -0
- package/README.md +2 -2
- package/dist/cjs/dialect/mysql/mysql-adapter.js +3 -4
- package/dist/cjs/dialect/mysql/mysql-introspector.js +2 -1
- package/dist/cjs/dialect/postgres/postgres-adapter.js +3 -2
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +2 -1
- package/dist/cjs/driver/connection-provider.d.ts +1 -1
- package/dist/cjs/driver/default-connection-provider.d.ts +1 -1
- package/dist/cjs/driver/default-connection-provider.js +1 -1
- package/dist/cjs/driver/single-connection-provider.d.ts +1 -1
- package/dist/cjs/driver/single-connection-provider.js +1 -1
- package/dist/cjs/index-nodeless.d.ts +2 -0
- package/dist/cjs/index-nodeless.js +2 -0
- package/dist/cjs/kysely.d.ts +3 -6
- package/dist/cjs/kysely.js +30 -41
- package/dist/cjs/migration/migrator.js +4 -4
- package/dist/cjs/operation-node/delete-query-node.d.ts +7 -0
- package/dist/cjs/operation-node/delete-query-node.js +15 -0
- package/dist/cjs/operation-node/operation-node-transformer.js +1 -1
- package/dist/cjs/operation-node/raw-node.d.ts +4 -2
- package/dist/cjs/operation-node/raw-node.js +8 -2
- package/dist/cjs/parser/complex-expression-parser.d.ts +5 -5
- package/dist/cjs/parser/complex-expression-parser.js +5 -4
- package/dist/cjs/parser/filter-parser.d.ts +9 -9
- package/dist/cjs/parser/filter-parser.js +31 -30
- package/dist/cjs/parser/group-by-parser.d.ts +1 -2
- package/dist/cjs/parser/group-by-parser.js +2 -2
- package/dist/cjs/parser/insert-values-parser.d.ts +1 -2
- package/dist/cjs/parser/insert-values-parser.js +6 -6
- package/dist/cjs/parser/join-parser.d.ts +1 -2
- package/dist/cjs/parser/join-parser.js +8 -7
- package/dist/cjs/parser/order-by-parser.d.ts +1 -2
- package/dist/cjs/parser/order-by-parser.js +4 -4
- package/dist/cjs/parser/parse-utils.d.ts +10 -0
- package/dist/cjs/parser/parse-utils.js +38 -0
- package/dist/cjs/parser/reference-parser.d.ts +2 -3
- package/dist/cjs/parser/reference-parser.js +5 -5
- package/dist/cjs/parser/select-parser.d.ts +1 -2
- package/dist/cjs/parser/select-parser.js +5 -5
- package/dist/cjs/parser/table-parser.d.ts +2 -3
- package/dist/cjs/parser/table-parser.js +5 -5
- package/dist/cjs/parser/update-set-parser.d.ts +1 -2
- package/dist/cjs/parser/update-set-parser.js +2 -2
- package/dist/cjs/parser/value-parser.d.ts +3 -4
- package/dist/cjs/parser/value-parser.js +7 -7
- package/dist/cjs/parser/with-parser.d.ts +1 -2
- package/dist/cjs/parser/with-parser.js +3 -2
- package/dist/cjs/query-builder/delete-query-builder.d.ts +77 -20
- package/dist/cjs/query-builder/delete-query-builder.js +81 -14
- package/dist/cjs/query-builder/expression-builder.d.ts +4 -13
- package/dist/cjs/query-builder/expression-builder.js +12 -21
- package/dist/cjs/query-builder/function-builder.d.ts +2 -6
- package/dist/cjs/query-builder/function-builder.js +5 -8
- package/dist/cjs/query-builder/insert-query-builder.d.ts +11 -9
- package/dist/cjs/query-builder/insert-query-builder.js +8 -7
- package/dist/cjs/query-builder/join-builder.d.ts +0 -2
- package/dist/cjs/query-builder/join-builder.js +8 -8
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +24 -20
- package/dist/cjs/query-builder/on-conflict-builder.js +17 -17
- package/dist/cjs/query-builder/returning-interface.d.ts +2 -2
- package/dist/cjs/query-builder/select-query-builder.d.ts +43 -32
- package/dist/cjs/query-builder/select-query-builder.js +28 -26
- package/dist/cjs/query-builder/update-query-builder.d.ts +29 -25
- package/dist/cjs/query-builder/update-query-builder.js +22 -20
- package/dist/cjs/query-builder/where-interface.d.ts +20 -16
- package/dist/cjs/query-compiler/default-query-compiler.js +16 -7
- package/dist/cjs/query-creator.d.ts +24 -138
- package/dist/cjs/query-creator.js +19 -145
- package/dist/cjs/query-executor/default-query-executor.d.ts +14 -3
- package/dist/cjs/query-executor/default-query-executor.js +15 -17
- package/dist/cjs/query-executor/noop-query-executor.d.ts +13 -2
- package/dist/cjs/query-executor/noop-query-executor.js +9 -2
- package/dist/cjs/query-executor/query-executor-provider.d.ts +8 -0
- package/dist/cjs/query-executor/query-executor-provider.js +2 -0
- package/dist/cjs/query-executor/query-executor.d.ts +14 -6
- package/dist/cjs/query-executor/query-executor.js +4 -2
- package/dist/cjs/raw-builder/raw-builder.d.ts +42 -11
- package/dist/cjs/raw-builder/raw-builder.js +55 -56
- package/dist/cjs/raw-builder/sql.d.ts +323 -0
- package/dist/cjs/raw-builder/sql.js +153 -0
- package/dist/cjs/schema/alter-table-builder.d.ts +20 -8
- package/dist/cjs/schema/alter-table-builder.js +3 -3
- package/dist/cjs/schema/column-definition-builder.d.ts +20 -8
- package/dist/cjs/schema/create-index-builder.d.ts +3 -1
- package/dist/cjs/schema/create-index-builder.js +3 -1
- package/dist/cjs/schema/create-table-builder.d.ts +6 -2
- package/dist/cjs/schema/create-table-builder.js +8 -4
- package/dist/cjs/schema/create-view-builder.d.ts +3 -3
- package/dist/cjs/schema/create-view-builder.js +3 -3
- package/dist/cjs/util/query-id.js +10 -4
- package/dist/cjs/util/random-string.js +65 -2
- package/dist/esm/dialect/mysql/mysql-adapter.js +3 -4
- package/dist/esm/dialect/mysql/mysql-introspector.js +2 -1
- package/dist/esm/dialect/postgres/postgres-adapter.js +3 -2
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +2 -1
- package/dist/esm/driver/connection-provider.d.ts +1 -1
- package/dist/esm/driver/default-connection-provider.d.ts +1 -1
- package/dist/esm/driver/default-connection-provider.js +1 -1
- package/dist/esm/driver/single-connection-provider.d.ts +1 -1
- package/dist/esm/driver/single-connection-provider.js +1 -1
- package/dist/esm/index-nodeless.d.ts +2 -0
- package/dist/esm/index-nodeless.js +2 -0
- package/dist/esm/kysely.d.ts +3 -6
- package/dist/esm/kysely.js +30 -41
- package/dist/esm/migration/migrator.js +4 -4
- package/dist/esm/operation-node/delete-query-node.d.ts +7 -0
- package/dist/esm/operation-node/delete-query-node.js +15 -0
- package/dist/esm/operation-node/operation-node-transformer.js +1 -1
- package/dist/esm/operation-node/raw-node.d.ts +4 -2
- package/dist/esm/operation-node/raw-node.js +8 -2
- package/dist/esm/parser/complex-expression-parser.d.ts +5 -5
- package/dist/esm/parser/complex-expression-parser.js +5 -4
- package/dist/esm/parser/filter-parser.d.ts +9 -9
- package/dist/esm/parser/filter-parser.js +31 -30
- package/dist/esm/parser/group-by-parser.d.ts +1 -2
- package/dist/esm/parser/group-by-parser.js +2 -2
- package/dist/esm/parser/insert-values-parser.d.ts +1 -2
- package/dist/esm/parser/insert-values-parser.js +6 -6
- package/dist/esm/parser/join-parser.d.ts +1 -2
- package/dist/esm/parser/join-parser.js +8 -7
- package/dist/esm/parser/order-by-parser.d.ts +1 -2
- package/dist/esm/parser/order-by-parser.js +4 -4
- package/dist/esm/parser/parse-utils.d.ts +10 -0
- package/dist/esm/parser/parse-utils.js +32 -0
- package/dist/esm/parser/reference-parser.d.ts +2 -3
- package/dist/esm/parser/reference-parser.js +5 -5
- package/dist/esm/parser/select-parser.d.ts +1 -2
- package/dist/esm/parser/select-parser.js +5 -5
- package/dist/esm/parser/table-parser.d.ts +2 -3
- package/dist/esm/parser/table-parser.js +5 -5
- package/dist/esm/parser/update-set-parser.d.ts +1 -2
- package/dist/esm/parser/update-set-parser.js +2 -2
- package/dist/esm/parser/value-parser.d.ts +3 -4
- package/dist/esm/parser/value-parser.js +7 -7
- package/dist/esm/parser/with-parser.d.ts +1 -2
- package/dist/esm/parser/with-parser.js +3 -2
- package/dist/esm/query-builder/delete-query-builder.d.ts +77 -20
- package/dist/esm/query-builder/delete-query-builder.js +81 -14
- package/dist/esm/query-builder/expression-builder.d.ts +4 -13
- package/dist/esm/query-builder/expression-builder.js +12 -21
- package/dist/esm/query-builder/function-builder.d.ts +2 -6
- package/dist/esm/query-builder/function-builder.js +5 -8
- package/dist/esm/query-builder/insert-query-builder.d.ts +11 -9
- package/dist/esm/query-builder/insert-query-builder.js +8 -7
- package/dist/esm/query-builder/join-builder.d.ts +0 -2
- package/dist/esm/query-builder/join-builder.js +8 -8
- package/dist/esm/query-builder/on-conflict-builder.d.ts +24 -20
- package/dist/esm/query-builder/on-conflict-builder.js +17 -17
- package/dist/esm/query-builder/returning-interface.d.ts +2 -2
- package/dist/esm/query-builder/select-query-builder.d.ts +43 -32
- package/dist/esm/query-builder/select-query-builder.js +28 -26
- package/dist/esm/query-builder/update-query-builder.d.ts +29 -25
- package/dist/esm/query-builder/update-query-builder.js +22 -20
- package/dist/esm/query-builder/where-interface.d.ts +20 -16
- package/dist/esm/query-compiler/default-query-compiler.js +16 -7
- package/dist/esm/query-creator.d.ts +24 -138
- package/dist/esm/query-creator.js +19 -145
- package/dist/esm/query-executor/default-query-executor.d.ts +14 -3
- package/dist/esm/query-executor/default-query-executor.js +15 -17
- package/dist/esm/query-executor/noop-query-executor.d.ts +13 -2
- package/dist/esm/query-executor/noop-query-executor.js +8 -1
- package/dist/esm/query-executor/query-executor-provider.d.ts +8 -0
- package/dist/esm/query-executor/query-executor-provider.js +2 -0
- package/dist/esm/query-executor/query-executor.d.ts +14 -6
- package/dist/esm/query-executor/query-executor.js +4 -2
- package/dist/esm/raw-builder/raw-builder.d.ts +42 -11
- package/dist/esm/raw-builder/raw-builder.js +56 -57
- package/dist/esm/raw-builder/sql.d.ts +323 -0
- package/dist/esm/raw-builder/sql.js +151 -0
- package/dist/esm/schema/alter-table-builder.d.ts +20 -8
- package/dist/esm/schema/alter-table-builder.js +3 -3
- package/dist/esm/schema/column-definition-builder.d.ts +20 -8
- package/dist/esm/schema/create-index-builder.d.ts +3 -1
- package/dist/esm/schema/create-index-builder.js +3 -1
- package/dist/esm/schema/create-table-builder.d.ts +6 -2
- package/dist/esm/schema/create-table-builder.js +8 -4
- package/dist/esm/schema/create-view-builder.d.ts +3 -3
- package/dist/esm/schema/create-view-builder.js +3 -3
- package/dist/esm/util/query-id.js +10 -4
- package/dist/esm/util/random-string.js +65 -2
- package/package.json +13 -13
- package/dist/cjs/parser/parse-context.d.ts +0 -55
- package/dist/cjs/parser/parse-context.js +0 -50
- package/dist/cjs/util/private-symbols.d.ts +0 -5
- package/dist/cjs/util/private-symbols.js +0 -8
- package/dist/esm/parser/parse-context.d.ts +0 -55
- package/dist/esm/parser/parse-context.js +0 -47
- package/dist/esm/util/private-symbols.d.ts +0 -5
- package/dist/esm/util/private-symbols.js +0 -6
|
@@ -2,7 +2,6 @@ import { OnConflictNode } from '../operation-node/on-conflict-node.js';
|
|
|
2
2
|
import { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
|
3
3
|
import { ComplexExpression } from '../parser/complex-expression-parser.js';
|
|
4
4
|
import { WhereGrouper, FilterOperator, FilterValueExpressionOrList } from '../parser/filter-parser.js';
|
|
5
|
-
import { ParseContext } from '../parser/parse-context.js';
|
|
6
5
|
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
7
6
|
import { MutationObject } from '../parser/update-set-parser.js';
|
|
8
7
|
import { AnyColumn, AnyRawBuilder } from '../util/type-utils.js';
|
|
@@ -70,7 +69,7 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
|
|
|
70
69
|
* ```
|
|
71
70
|
*
|
|
72
71
|
* Operator can be any supported operator or if the typings don't support it
|
|
73
|
-
* you can always use `
|
|
72
|
+
* you can always use `sql\`your operator\``.
|
|
74
73
|
*
|
|
75
74
|
* ```ts
|
|
76
75
|
* const persons = await db
|
|
@@ -140,7 +139,7 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
|
|
|
140
139
|
*
|
|
141
140
|
* A `where in` query can be built by using the `in` operator and an array
|
|
142
141
|
* of values. The values in the array can also be subqueries or raw
|
|
143
|
-
*
|
|
142
|
+
* {@link sql} expressions.
|
|
144
143
|
*
|
|
145
144
|
* ```ts
|
|
146
145
|
* const persons = await db
|
|
@@ -156,15 +155,17 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
|
|
|
156
155
|
* select * from "person" where "id" in ($1, $2, $3)
|
|
157
156
|
* ```
|
|
158
157
|
*
|
|
159
|
-
* If everything else fails, you can always
|
|
158
|
+
* If everything else fails, you can always use the {@link sql} tag
|
|
160
159
|
* as any of the arguments, including the operator:
|
|
161
160
|
*
|
|
162
161
|
* ```ts
|
|
162
|
+
* import { sql } from 'kysely'
|
|
163
|
+
*
|
|
163
164
|
* const persons = await db
|
|
164
165
|
* .selectFrom('person')
|
|
165
166
|
* .selectAll()
|
|
166
167
|
* .where(
|
|
167
|
-
*
|
|
168
|
+
* sql`coalesce(first_name, last_name)`,
|
|
168
169
|
* 'like',
|
|
169
170
|
* '%' + name + '%',
|
|
170
171
|
* )
|
|
@@ -199,24 +200,25 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
|
|
|
199
200
|
* ```
|
|
200
201
|
*
|
|
201
202
|
* In all examples above the columns were known at compile time
|
|
202
|
-
* (except for the
|
|
203
|
-
* you to refer to columns that exist in the database **and**
|
|
204
|
-
* referred to in the current query and context.
|
|
203
|
+
* (except for the raw {@link sql} expressions). By default kysely only
|
|
204
|
+
* allows you to refer to columns that exist in the database **and**
|
|
205
|
+
* can be referred to in the current query and context.
|
|
205
206
|
*
|
|
206
207
|
* Sometimes you may want to refer to columns that come from the user
|
|
207
208
|
* input and thus are not available at compile time.
|
|
208
209
|
*
|
|
209
|
-
* You have two options,
|
|
210
|
+
* You have two options, the {@link sql} tag or `db.dynamic`. The example below
|
|
210
211
|
* uses both:
|
|
211
212
|
*
|
|
212
213
|
* ```ts
|
|
214
|
+
* import { sql } from 'kysely'
|
|
213
215
|
* const { ref } = db.dynamic
|
|
214
216
|
*
|
|
215
217
|
* const persons = await db
|
|
216
218
|
* .selectFrom('person')
|
|
217
219
|
* .selectAll()
|
|
218
220
|
* .where(ref(columnFromUserInput), '=', 1)
|
|
219
|
-
* .orWhere(
|
|
221
|
+
* .orWhere(sql.id(columnFromUserInput), '=', 2)
|
|
220
222
|
* .execute()
|
|
221
223
|
* ```
|
|
222
224
|
*/
|
|
@@ -381,7 +383,6 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
|
|
|
381
383
|
}
|
|
382
384
|
export interface OnConflictBuilderProps {
|
|
383
385
|
readonly onConflictNode: OnConflictNode;
|
|
384
|
-
readonly parseContext: ParseContext;
|
|
385
386
|
}
|
|
386
387
|
export declare type OnConflictDatabase<DB, TB extends keyof DB> = {
|
|
387
388
|
[K in keyof DB | 'excluded']: K extends keyof DB ? DB[K] : DB[TB];
|
|
@@ -425,7 +426,7 @@ export declare class OnConflictUpdateBuilder<DB, TB extends keyof DB> implements
|
|
|
425
426
|
* ```
|
|
426
427
|
*
|
|
427
428
|
* Operator can be any supported operator or if the typings don't support it
|
|
428
|
-
* you can always use `
|
|
429
|
+
* you can always use `sql\`your operator\``.
|
|
429
430
|
*
|
|
430
431
|
* ```ts
|
|
431
432
|
* const persons = await db
|
|
@@ -495,7 +496,7 @@ export declare class OnConflictUpdateBuilder<DB, TB extends keyof DB> implements
|
|
|
495
496
|
*
|
|
496
497
|
* A `where in` query can be built by using the `in` operator and an array
|
|
497
498
|
* of values. The values in the array can also be subqueries or raw
|
|
498
|
-
*
|
|
499
|
+
* {@link sql} expressions.
|
|
499
500
|
*
|
|
500
501
|
* ```ts
|
|
501
502
|
* const persons = await db
|
|
@@ -511,15 +512,17 @@ export declare class OnConflictUpdateBuilder<DB, TB extends keyof DB> implements
|
|
|
511
512
|
* select * from "person" where "id" in ($1, $2, $3)
|
|
512
513
|
* ```
|
|
513
514
|
*
|
|
514
|
-
* If everything else fails, you can always
|
|
515
|
+
* If everything else fails, you can always use the {@link sql} tag
|
|
515
516
|
* as any of the arguments, including the operator:
|
|
516
517
|
*
|
|
517
518
|
* ```ts
|
|
519
|
+
* import { sql } from 'kysely'
|
|
520
|
+
*
|
|
518
521
|
* const persons = await db
|
|
519
522
|
* .selectFrom('person')
|
|
520
523
|
* .selectAll()
|
|
521
524
|
* .where(
|
|
522
|
-
*
|
|
525
|
+
* sql`coalesce(first_name, last_name)`,
|
|
523
526
|
* 'like',
|
|
524
527
|
* '%' + name + '%',
|
|
525
528
|
* )
|
|
@@ -554,24 +557,25 @@ export declare class OnConflictUpdateBuilder<DB, TB extends keyof DB> implements
|
|
|
554
557
|
* ```
|
|
555
558
|
*
|
|
556
559
|
* In all examples above the columns were known at compile time
|
|
557
|
-
* (except for the
|
|
558
|
-
* you to refer to columns that exist in the database **and**
|
|
559
|
-
* referred to in the current query and context.
|
|
560
|
+
* (except for the raw {@link sql} expressions). By default kysely only
|
|
561
|
+
* allows you to refer to columns that exist in the database **and**
|
|
562
|
+
* can be referred to in the current query and context.
|
|
560
563
|
*
|
|
561
564
|
* Sometimes you may want to refer to columns that come from the user
|
|
562
565
|
* input and thus are not available at compile time.
|
|
563
566
|
*
|
|
564
|
-
* You have two options,
|
|
567
|
+
* You have two options, the {@link sql} tag or `db.dynamic`. The example below
|
|
565
568
|
* uses both:
|
|
566
569
|
*
|
|
567
570
|
* ```ts
|
|
571
|
+
* import { sql } from 'kysely'
|
|
568
572
|
* const { ref } = db.dynamic
|
|
569
573
|
*
|
|
570
574
|
* const persons = await db
|
|
571
575
|
* .selectFrom('person')
|
|
572
576
|
* .selectAll()
|
|
573
577
|
* .where(ref(columnFromUserInput), '=', 1)
|
|
574
|
-
* .orWhere(
|
|
578
|
+
* .orWhere(sql.id(columnFromUserInput), '=', 2)
|
|
575
579
|
* .execute()
|
|
576
580
|
* ```
|
|
577
581
|
*/
|
|
@@ -78,7 +78,7 @@ export class OnConflictBuilder {
|
|
|
78
78
|
where(...args) {
|
|
79
79
|
return new OnConflictBuilder({
|
|
80
80
|
...this.#props,
|
|
81
|
-
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseWhereFilter(
|
|
81
|
+
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseWhereFilter(args)),
|
|
82
82
|
});
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
@@ -89,13 +89,13 @@ export class OnConflictBuilder {
|
|
|
89
89
|
whereRef(lhs, op, rhs) {
|
|
90
90
|
return new OnConflictBuilder({
|
|
91
91
|
...this.#props,
|
|
92
|
-
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseReferenceFilter(
|
|
92
|
+
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseReferenceFilter(lhs, op, rhs)),
|
|
93
93
|
});
|
|
94
94
|
}
|
|
95
95
|
orWhere(...args) {
|
|
96
96
|
return new OnConflictBuilder({
|
|
97
97
|
...this.#props,
|
|
98
|
-
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseWhereFilter(
|
|
98
|
+
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseWhereFilter(args)),
|
|
99
99
|
});
|
|
100
100
|
}
|
|
101
101
|
/**
|
|
@@ -106,7 +106,7 @@ export class OnConflictBuilder {
|
|
|
106
106
|
orWhereRef(lhs, op, rhs) {
|
|
107
107
|
return new OnConflictBuilder({
|
|
108
108
|
...this.#props,
|
|
109
|
-
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseReferenceFilter(
|
|
109
|
+
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseReferenceFilter(lhs, op, rhs)),
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
@@ -117,7 +117,7 @@ export class OnConflictBuilder {
|
|
|
117
117
|
whereExists(arg) {
|
|
118
118
|
return new OnConflictBuilder({
|
|
119
119
|
...this.#props,
|
|
120
|
-
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseExistFilter(
|
|
120
|
+
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseExistFilter(arg)),
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
/**
|
|
@@ -128,7 +128,7 @@ export class OnConflictBuilder {
|
|
|
128
128
|
whereNotExists(arg) {
|
|
129
129
|
return new OnConflictBuilder({
|
|
130
130
|
...this.#props,
|
|
131
|
-
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseNotExistFilter(
|
|
131
|
+
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseNotExistFilter(arg)),
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
@@ -139,7 +139,7 @@ export class OnConflictBuilder {
|
|
|
139
139
|
orWhereExists(arg) {
|
|
140
140
|
return new OnConflictBuilder({
|
|
141
141
|
...this.#props,
|
|
142
|
-
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseExistFilter(
|
|
142
|
+
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseExistFilter(arg)),
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
/**
|
|
@@ -150,7 +150,7 @@ export class OnConflictBuilder {
|
|
|
150
150
|
orWhereNotExists(arg) {
|
|
151
151
|
return new OnConflictBuilder({
|
|
152
152
|
...this.#props,
|
|
153
|
-
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseNotExistFilter(
|
|
153
|
+
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseNotExistFilter(arg)),
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
@@ -212,7 +212,7 @@ export class OnConflictBuilder {
|
|
|
212
212
|
return new OnConflictUpdateBuilder({
|
|
213
213
|
...this.#props,
|
|
214
214
|
onConflictNode: OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
215
|
-
updates: parseUpdateObject(
|
|
215
|
+
updates: parseUpdateObject(updates),
|
|
216
216
|
}),
|
|
217
217
|
});
|
|
218
218
|
}
|
|
@@ -236,7 +236,7 @@ export class OnConflictUpdateBuilder {
|
|
|
236
236
|
where(...args) {
|
|
237
237
|
return new OnConflictUpdateBuilder({
|
|
238
238
|
...this.#props,
|
|
239
|
-
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseWhereFilter(
|
|
239
|
+
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseWhereFilter(args)),
|
|
240
240
|
});
|
|
241
241
|
}
|
|
242
242
|
/**
|
|
@@ -247,13 +247,13 @@ export class OnConflictUpdateBuilder {
|
|
|
247
247
|
whereRef(lhs, op, rhs) {
|
|
248
248
|
return new OnConflictUpdateBuilder({
|
|
249
249
|
...this.#props,
|
|
250
|
-
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseReferenceFilter(
|
|
250
|
+
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseReferenceFilter(lhs, op, rhs)),
|
|
251
251
|
});
|
|
252
252
|
}
|
|
253
253
|
orWhere(...args) {
|
|
254
254
|
return new OnConflictUpdateBuilder({
|
|
255
255
|
...this.#props,
|
|
256
|
-
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseWhereFilter(
|
|
256
|
+
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseWhereFilter(args)),
|
|
257
257
|
});
|
|
258
258
|
}
|
|
259
259
|
/**
|
|
@@ -264,7 +264,7 @@ export class OnConflictUpdateBuilder {
|
|
|
264
264
|
orWhereRef(lhs, op, rhs) {
|
|
265
265
|
return new OnConflictUpdateBuilder({
|
|
266
266
|
...this.#props,
|
|
267
|
-
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseReferenceFilter(
|
|
267
|
+
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseReferenceFilter(lhs, op, rhs)),
|
|
268
268
|
});
|
|
269
269
|
}
|
|
270
270
|
/**
|
|
@@ -275,7 +275,7 @@ export class OnConflictUpdateBuilder {
|
|
|
275
275
|
whereExists(arg) {
|
|
276
276
|
return new OnConflictUpdateBuilder({
|
|
277
277
|
...this.#props,
|
|
278
|
-
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseExistFilter(
|
|
278
|
+
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseExistFilter(arg)),
|
|
279
279
|
});
|
|
280
280
|
}
|
|
281
281
|
/**
|
|
@@ -286,7 +286,7 @@ export class OnConflictUpdateBuilder {
|
|
|
286
286
|
whereNotExists(arg) {
|
|
287
287
|
return new OnConflictUpdateBuilder({
|
|
288
288
|
...this.#props,
|
|
289
|
-
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseNotExistFilter(
|
|
289
|
+
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseNotExistFilter(arg)),
|
|
290
290
|
});
|
|
291
291
|
}
|
|
292
292
|
/**
|
|
@@ -297,7 +297,7 @@ export class OnConflictUpdateBuilder {
|
|
|
297
297
|
orWhereExists(arg) {
|
|
298
298
|
return new OnConflictUpdateBuilder({
|
|
299
299
|
...this.#props,
|
|
300
|
-
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseExistFilter(
|
|
300
|
+
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseExistFilter(arg)),
|
|
301
301
|
});
|
|
302
302
|
}
|
|
303
303
|
/**
|
|
@@ -308,7 +308,7 @@ export class OnConflictUpdateBuilder {
|
|
|
308
308
|
orWhereNotExists(arg) {
|
|
309
309
|
return new OnConflictUpdateBuilder({
|
|
310
310
|
...this.#props,
|
|
311
|
-
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseNotExistFilter(
|
|
311
|
+
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseNotExistFilter(arg)),
|
|
312
312
|
});
|
|
313
313
|
}
|
|
314
314
|
toOperationNode() {
|
|
@@ -45,7 +45,7 @@ export interface ReturningInterface<DB, TB extends keyof DB, O> {
|
|
|
45
45
|
* Return arbitrary expressions:
|
|
46
46
|
*
|
|
47
47
|
* ```ts
|
|
48
|
-
*
|
|
48
|
+
* import { sql } from 'kysely'
|
|
49
49
|
*
|
|
50
50
|
* const { id, full_name, first_pet_id } = await db
|
|
51
51
|
* .insertInto('person')
|
|
@@ -55,7 +55,7 @@ export interface ReturningInterface<DB, TB extends keyof DB, O> {
|
|
|
55
55
|
* })
|
|
56
56
|
* .returning([
|
|
57
57
|
* 'id as id',
|
|
58
|
-
*
|
|
58
|
+
* sql<string>`concat(first_name, ' ', last_name)`.as('full_name'),
|
|
59
59
|
* (qb) => qb.selectFrom('pets').select('pet.id').limit(1).as('first_pet_id')
|
|
60
60
|
* ])
|
|
61
61
|
* .executeTakeFirst()
|
|
@@ -12,7 +12,6 @@ import { OrderByDirectionExpression, OrderByExpression } from '../parser/order-b
|
|
|
12
12
|
import { Compilable } from '../util/compilable.js';
|
|
13
13
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
14
14
|
import { QueryId } from '../util/query-id.js';
|
|
15
|
-
import { ParseContext } from '../parser/parse-context.js';
|
|
16
15
|
import { UnionExpression } from '../parser/union-parser.js';
|
|
17
16
|
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
18
17
|
import { WhereInterface } from './where-interface.js';
|
|
@@ -46,7 +45,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
46
45
|
* ```
|
|
47
46
|
*
|
|
48
47
|
* Operator can be any supported operator or if the typings don't support it
|
|
49
|
-
* you can always use `
|
|
48
|
+
* you can always use `sql\`your operator\``.
|
|
50
49
|
*
|
|
51
50
|
* ```ts
|
|
52
51
|
* const persons = await db
|
|
@@ -116,7 +115,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
116
115
|
*
|
|
117
116
|
* A `where in` query can be built by using the `in` operator and an array
|
|
118
117
|
* of values. The values in the array can also be subqueries or raw
|
|
119
|
-
*
|
|
118
|
+
* {@link sql} expressions.
|
|
120
119
|
*
|
|
121
120
|
* ```ts
|
|
122
121
|
* const persons = await db
|
|
@@ -132,15 +131,17 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
132
131
|
* select * from "person" where "id" in ($1, $2, $3)
|
|
133
132
|
* ```
|
|
134
133
|
*
|
|
135
|
-
* If everything else fails, you can always
|
|
134
|
+
* If everything else fails, you can always use the {@link sql} tag
|
|
136
135
|
* as any of the arguments, including the operator:
|
|
137
136
|
*
|
|
138
137
|
* ```ts
|
|
138
|
+
* import { sql } from 'kysely'
|
|
139
|
+
*
|
|
139
140
|
* const persons = await db
|
|
140
141
|
* .selectFrom('person')
|
|
141
142
|
* .selectAll()
|
|
142
143
|
* .where(
|
|
143
|
-
*
|
|
144
|
+
* sql`coalesce(first_name, last_name)`,
|
|
144
145
|
* 'like',
|
|
145
146
|
* '%' + name + '%',
|
|
146
147
|
* )
|
|
@@ -175,24 +176,25 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
175
176
|
* ```
|
|
176
177
|
*
|
|
177
178
|
* In all examples above the columns were known at compile time
|
|
178
|
-
* (except for the
|
|
179
|
-
* you to refer to columns that exist in the database **and**
|
|
180
|
-
* referred to in the current query and context.
|
|
179
|
+
* (except for the raw {@link sql} expressions). By default kysely only
|
|
180
|
+
* allows you to refer to columns that exist in the database **and**
|
|
181
|
+
* can be referred to in the current query and context.
|
|
181
182
|
*
|
|
182
183
|
* Sometimes you may want to refer to columns that come from the user
|
|
183
184
|
* input and thus are not available at compile time.
|
|
184
185
|
*
|
|
185
|
-
* You have two options,
|
|
186
|
+
* You have two options, the {@link sql} tag or `db.dynamic`. The example below
|
|
186
187
|
* uses both:
|
|
187
188
|
*
|
|
188
189
|
* ```ts
|
|
190
|
+
* import { sql } from 'kysely'
|
|
189
191
|
* const { ref } = db.dynamic
|
|
190
192
|
*
|
|
191
193
|
* const persons = await db
|
|
192
194
|
* .selectFrom('person')
|
|
193
195
|
* .selectAll()
|
|
194
196
|
* .where(ref(columnFromUserInput), '=', 1)
|
|
195
|
-
* .orWhere(
|
|
197
|
+
* .orWhere(sql.id(columnFromUserInput), '=', 2)
|
|
196
198
|
* .execute()
|
|
197
199
|
* ```
|
|
198
200
|
*/
|
|
@@ -326,13 +328,14 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
326
328
|
/**
|
|
327
329
|
* Adds a `where exists` clause to the query.
|
|
328
330
|
*
|
|
329
|
-
* You can either use a subquery or a raw
|
|
331
|
+
* You can either use a subquery or a raw {@link sql} snippet.
|
|
330
332
|
*
|
|
331
333
|
* ### Examples
|
|
332
334
|
*
|
|
333
335
|
* The query below selets all persons that own a pet named Catto:
|
|
334
336
|
*
|
|
335
337
|
* ```ts
|
|
338
|
+
* const petName = 'Catto'
|
|
336
339
|
* const persons = await db
|
|
337
340
|
* .selectFrom('person')
|
|
338
341
|
* .selectAll()
|
|
@@ -340,7 +343,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
340
343
|
* .selectFrom('pet')
|
|
341
344
|
* .select('pet.id')
|
|
342
345
|
* .whereRef('person.id', '=', 'pet.owner_id')
|
|
343
|
-
* .where('pet.name', '=',
|
|
346
|
+
* .where('pet.name', '=', petName)
|
|
344
347
|
* )
|
|
345
348
|
* .execute()
|
|
346
349
|
* ```
|
|
@@ -357,16 +360,16 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
357
360
|
* )
|
|
358
361
|
* ```
|
|
359
362
|
*
|
|
360
|
-
* The same query as in the previous example but with using raw:
|
|
363
|
+
* The same query as in the previous example but with using raw {@link sql}:
|
|
361
364
|
*
|
|
362
365
|
* ```ts
|
|
366
|
+
* import { sql } from 'kysely'
|
|
367
|
+
*
|
|
368
|
+
* const petName = 'Catto'
|
|
363
369
|
* db.selectFrom('person')
|
|
364
370
|
* .selectAll()
|
|
365
371
|
* .whereExists(
|
|
366
|
-
*
|
|
367
|
-
* '(select pet.id from pet where person.id = pet.owner_id and pet.name = ?)',
|
|
368
|
-
* ['Catto']
|
|
369
|
-
* )
|
|
372
|
+
* sql`(select pet.id from pet where person.id = pet.owner_id and pet.name = ${petName})`
|
|
370
373
|
* )
|
|
371
374
|
* ```
|
|
372
375
|
*
|
|
@@ -449,14 +452,17 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
449
452
|
* Kysely only allows you to select columns and expressions that exist and would
|
|
450
453
|
* produce valid SQL. However, Kysely is not perfect and there may be cases where
|
|
451
454
|
* the type inference doesn't work and you need to override it. You can always
|
|
452
|
-
* use the {@link Kysely.dynamic | dynamic} module and {@link
|
|
455
|
+
* use the {@link Kysely.dynamic | dynamic} module and the {@link sql} tag
|
|
453
456
|
* to override the types.
|
|
454
457
|
*
|
|
455
458
|
* Select calls are additive. Calling `select('id').select('first_name')` is the
|
|
456
459
|
* same as calling `select(['id', 'first_name']).
|
|
457
460
|
*
|
|
458
461
|
* To select all columns of the query or specific tables see the
|
|
459
|
-
* {@link
|
|
462
|
+
* {@link selectAll} method.
|
|
463
|
+
*
|
|
464
|
+
* See the {@link if} method if you are looking for a way to add selections
|
|
465
|
+
* based on a runtime condition.
|
|
460
466
|
*
|
|
461
467
|
* ### Examples
|
|
462
468
|
*
|
|
@@ -533,11 +539,13 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
533
539
|
* from "person"
|
|
534
540
|
* ```
|
|
535
541
|
*
|
|
536
|
-
* You can also select subqueries and raw expressions. Note that you
|
|
542
|
+
* You can also select subqueries and raw sql expressions. Note that you
|
|
537
543
|
* always need to give a name for the selections using the `as`
|
|
538
544
|
* method:
|
|
539
545
|
*
|
|
540
546
|
* ```ts
|
|
547
|
+
* import { sql } from 'kysely'
|
|
548
|
+
*
|
|
541
549
|
* const persons = await db.selectFrom('person')
|
|
542
550
|
* .select([
|
|
543
551
|
* (qb) => qb
|
|
@@ -546,7 +554,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
546
554
|
* .select('pet.name')
|
|
547
555
|
* .limit(1)
|
|
548
556
|
* .as('pet_name')
|
|
549
|
-
*
|
|
557
|
+
* sql<string>`concat(first_name, ' ', last_name)`.as('full_name')
|
|
550
558
|
* ])
|
|
551
559
|
* .execute()
|
|
552
560
|
*
|
|
@@ -568,7 +576,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
568
576
|
* from "person"
|
|
569
577
|
* ```
|
|
570
578
|
*
|
|
571
|
-
* In case you use
|
|
579
|
+
* In case you use the {@link sql} tag you need to specify the type of the expression
|
|
572
580
|
* (in this example `string`).
|
|
573
581
|
*
|
|
574
582
|
* All the examples above assume you know the column names at compile time.
|
|
@@ -886,10 +894,12 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
886
894
|
* order by "id" asc, "fn" desc
|
|
887
895
|
* ```
|
|
888
896
|
*
|
|
889
|
-
* The order by expression can also be a
|
|
897
|
+
* The order by expression can also be a raw sql expression or a subquery
|
|
890
898
|
* in addition to column references:
|
|
891
899
|
*
|
|
892
900
|
* ```ts
|
|
901
|
+
* import { sql } from 'kysely'
|
|
902
|
+
*
|
|
893
903
|
* await db
|
|
894
904
|
* .selectFrom('person')
|
|
895
905
|
* .selectAll()
|
|
@@ -899,7 +909,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
899
909
|
* .limit(1)
|
|
900
910
|
* )
|
|
901
911
|
* .orderBy(
|
|
902
|
-
*
|
|
912
|
+
* sql`concat(first_name, last_name)`
|
|
903
913
|
* )
|
|
904
914
|
* .execute()
|
|
905
915
|
* ```
|
|
@@ -950,11 +960,13 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
950
960
|
* ### Examples
|
|
951
961
|
*
|
|
952
962
|
* ```ts
|
|
963
|
+
* import { sql } from 'kysely'
|
|
964
|
+
*
|
|
953
965
|
* await db
|
|
954
966
|
* .selectFrom('person')
|
|
955
967
|
* .select([
|
|
956
968
|
* 'first_name',
|
|
957
|
-
*
|
|
969
|
+
* sql`max(id)`.as('max_id')
|
|
958
970
|
* ])
|
|
959
971
|
* .groupBy('first_name')
|
|
960
972
|
* .execute()
|
|
@@ -971,14 +983,14 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
971
983
|
* `groupBy` also accepts an array:
|
|
972
984
|
*
|
|
973
985
|
* ```ts
|
|
974
|
-
*
|
|
986
|
+
* import { sql } from 'kysely'
|
|
975
987
|
*
|
|
976
988
|
* await db
|
|
977
989
|
* .selectFrom('person')
|
|
978
990
|
* .select([
|
|
979
991
|
* 'first_name',
|
|
980
992
|
* 'last_name',
|
|
981
|
-
*
|
|
993
|
+
* sql`max(id)`.as('max_id')
|
|
982
994
|
* ])
|
|
983
995
|
* .groupBy([
|
|
984
996
|
* 'first_name',
|
|
@@ -996,20 +1008,20 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
996
1008
|
* ```
|
|
997
1009
|
*
|
|
998
1010
|
* The group by expressions can also be subqueries or
|
|
999
|
-
* raw expressions:
|
|
1011
|
+
* raw sql expressions:
|
|
1000
1012
|
*
|
|
1001
1013
|
* ```ts
|
|
1002
|
-
*
|
|
1014
|
+
* import { sql } from 'kysely'
|
|
1003
1015
|
*
|
|
1004
1016
|
* await db
|
|
1005
1017
|
* .selectFrom('person')
|
|
1006
1018
|
* .select([
|
|
1007
1019
|
* 'first_name',
|
|
1008
1020
|
* 'last_name',
|
|
1009
|
-
*
|
|
1021
|
+
* sql`max(id)`.as('max_id')
|
|
1010
1022
|
* ])
|
|
1011
1023
|
* .groupBy([
|
|
1012
|
-
*
|
|
1024
|
+
* sql`concat(first_name, last_name)`,
|
|
1013
1025
|
* (qb) => qb.selectFrom('pet').select('id').limit(1)
|
|
1014
1026
|
* ])
|
|
1015
1027
|
* .execute()
|
|
@@ -1243,7 +1255,6 @@ export interface SelectQueryBuilderProps {
|
|
|
1243
1255
|
readonly queryId: QueryId;
|
|
1244
1256
|
readonly queryNode: SelectQueryNode;
|
|
1245
1257
|
readonly executor: QueryExecutor;
|
|
1246
|
-
readonly parseContext: ParseContext;
|
|
1247
1258
|
}
|
|
1248
1259
|
/**
|
|
1249
1260
|
* {@link SelectQueryBuilder} with an alias. The result of calling {@link SelectQueryBuilder.as}.
|