kysely 0.13.0 → 0.15.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/README.md +92 -32
- package/dist/cjs/{introspection → dialect}/database-introspector.d.ts +0 -0
- package/dist/cjs/{introspection → dialect}/database-introspector.js +0 -0
- package/dist/cjs/dialect/dialect.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +3 -3
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +3 -3
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +3 -3
- package/dist/cjs/index.d.ts +6 -3
- package/dist/cjs/index.js +6 -3
- package/dist/cjs/kysely.d.ts +8 -40
- package/dist/cjs/kysely.js +8 -40
- package/dist/cjs/migration/file-migration-provider.d.ts +52 -0
- package/dist/cjs/migration/file-migration-provider.js +52 -0
- package/dist/{esm/migration/migration.d.ts → cjs/migration/migrator.d.ts} +159 -134
- package/dist/cjs/migration/{migration.js → migrator.js} +166 -57
- package/dist/cjs/operation-node/check-constraint-node.d.ts +1 -1
- package/dist/cjs/operation-node/check-constraint-node.js +2 -3
- package/dist/cjs/operation-node/column-definition-node.d.ts +2 -2
- package/dist/cjs/operation-node/data-type-node.d.ts +1 -1
- package/dist/cjs/operation-node/generated-node.d.ts +20 -0
- package/dist/cjs/operation-node/generated-node.js +31 -0
- package/dist/cjs/operation-node/on-conflict-node.d.ts +13 -2
- package/dist/cjs/operation-node/on-conflict-node.js +39 -1
- package/dist/cjs/operation-node/operation-node-transformer.d.ts +2 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +11 -5
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +2 -2
- package/dist/cjs/operation-node/operation-node-visitor.js +1 -1
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/parser/insert-values-parser.d.ts +4 -4
- package/dist/cjs/parser/insert-values-parser.js +2 -3
- package/dist/cjs/parser/reference-parser.d.ts +4 -3
- package/dist/cjs/parser/select-parser.d.ts +10 -4
- package/dist/cjs/parser/update-set-parser.d.ts +2 -1
- package/dist/cjs/query-builder/delete-query-builder.d.ts +2 -4
- package/dist/cjs/query-builder/insert-query-builder.d.ts +80 -95
- package/dist/cjs/query-builder/insert-query-builder.js +145 -15
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +686 -0
- package/dist/cjs/query-builder/on-conflict-builder.js +323 -0
- package/dist/cjs/query-builder/returning-interface.d.ts +2 -4
- package/dist/cjs/query-builder/select-query-builder.d.ts +1 -1
- package/dist/cjs/query-builder/update-query-builder.d.ts +2 -4
- package/dist/cjs/query-compiler/default-query-compiler.d.ts +2 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +33 -7
- package/dist/cjs/query-creator.d.ts +0 -2
- package/dist/cjs/query-creator.js +0 -2
- package/dist/cjs/schema/alter-table-builder.d.ts +29 -9
- package/dist/cjs/schema/alter-table-builder.js +33 -9
- package/dist/cjs/schema/column-definition-builder.d.ts +28 -8
- package/dist/cjs/schema/column-definition-builder.js +17 -7
- package/dist/cjs/schema/create-index-builder.d.ts +3 -2
- package/dist/cjs/schema/create-index-builder.js +2 -2
- package/dist/cjs/schema/create-table-builder.d.ts +3 -2
- package/dist/cjs/schema/create-table-builder.js +2 -2
- package/dist/cjs/util/column-type.d.ts +165 -0
- package/dist/cjs/util/column-type.js +2 -0
- package/dist/cjs/util/private-symbols.d.ts +5 -0
- package/dist/cjs/util/private-symbols.js +8 -0
- package/dist/cjs/util/type-utils.d.ts +6 -42
- package/dist/esm/{introspection → dialect}/database-introspector.d.ts +0 -0
- package/dist/esm/{introspection → dialect}/database-introspector.js +0 -0
- package/dist/esm/dialect/dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +1 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +1 -1
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +1 -1
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +1 -1
- package/dist/esm/index.d.ts +6 -3
- package/dist/esm/index.js +6 -3
- package/dist/esm/kysely.d.ts +8 -40
- package/dist/esm/kysely.js +8 -40
- package/dist/esm/migration/file-migration-provider.d.ts +52 -0
- package/dist/esm/migration/file-migration-provider.js +48 -0
- package/dist/{cjs/migration/migration.d.ts → esm/migration/migrator.d.ts} +159 -134
- package/dist/esm/migration/{migration.js → migrator.js} +165 -56
- package/dist/esm/operation-node/check-constraint-node.d.ts +1 -1
- package/dist/esm/operation-node/check-constraint-node.js +2 -3
- package/dist/esm/operation-node/column-definition-node.d.ts +2 -2
- package/dist/esm/operation-node/data-type-node.d.ts +1 -1
- package/dist/esm/operation-node/generated-node.d.ts +20 -0
- package/dist/esm/operation-node/generated-node.js +28 -0
- package/dist/esm/operation-node/on-conflict-node.d.ts +13 -2
- package/dist/esm/operation-node/on-conflict-node.js +39 -1
- package/dist/esm/operation-node/operation-node-transformer.d.ts +2 -2
- package/dist/esm/operation-node/operation-node-transformer.js +11 -5
- package/dist/esm/operation-node/operation-node-visitor.d.ts +2 -2
- package/dist/esm/operation-node/operation-node-visitor.js +1 -1
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/parser/insert-values-parser.d.ts +4 -4
- package/dist/esm/parser/insert-values-parser.js +2 -3
- package/dist/esm/parser/reference-parser.d.ts +4 -3
- package/dist/esm/parser/select-parser.d.ts +10 -4
- package/dist/esm/parser/update-set-parser.d.ts +2 -1
- package/dist/esm/query-builder/delete-query-builder.d.ts +2 -4
- package/dist/esm/query-builder/insert-query-builder.d.ts +80 -95
- package/dist/esm/query-builder/insert-query-builder.js +145 -15
- package/dist/esm/query-builder/on-conflict-builder.d.ts +686 -0
- package/dist/esm/query-builder/on-conflict-builder.js +317 -0
- package/dist/esm/query-builder/returning-interface.d.ts +2 -4
- package/dist/esm/query-builder/select-query-builder.d.ts +1 -1
- package/dist/esm/query-builder/update-query-builder.d.ts +2 -4
- package/dist/esm/query-compiler/default-query-compiler.d.ts +2 -2
- package/dist/esm/query-compiler/default-query-compiler.js +33 -7
- package/dist/esm/query-creator.d.ts +0 -2
- package/dist/esm/query-creator.js +0 -2
- package/dist/esm/schema/alter-table-builder.d.ts +29 -9
- package/dist/esm/schema/alter-table-builder.js +33 -9
- package/dist/esm/schema/column-definition-builder.d.ts +28 -8
- package/dist/esm/schema/column-definition-builder.js +17 -7
- package/dist/esm/schema/create-index-builder.d.ts +3 -2
- package/dist/esm/schema/create-index-builder.js +2 -2
- package/dist/esm/schema/create-table-builder.d.ts +3 -2
- package/dist/esm/schema/create-table-builder.js +2 -2
- package/dist/esm/util/column-type.d.ts +165 -0
- package/dist/esm/util/column-type.js +1 -0
- package/dist/esm/util/private-symbols.d.ts +5 -0
- package/dist/esm/util/private-symbols.js +5 -0
- package/dist/esm/util/type-utils.d.ts +6 -42
- package/package.json +1 -1
- package/dist/cjs/operation-node/generated-always-as-node.d.ts +0 -16
- package/dist/cjs/operation-node/generated-always-as-node.js +0 -25
- package/dist/cjs/parser/on-conflict-parser.d.ts +0 -10
- package/dist/cjs/parser/on-conflict-parser.js +0 -35
- package/dist/cjs/util/generated-placeholder.d.ts +0 -3
- package/dist/cjs/util/generated-placeholder.js +0 -11
- package/dist/esm/operation-node/generated-always-as-node.d.ts +0 -16
- package/dist/esm/operation-node/generated-always-as-node.js +0 -22
- package/dist/esm/parser/on-conflict-parser.d.ts +0 -10
- package/dist/esm/parser/on-conflict-parser.js +0 -30
- package/dist/esm/util/generated-placeholder.d.ts +0 -3
- package/dist/esm/util/generated-placeholder.js +0 -7
|
@@ -0,0 +1,686 @@
|
|
|
1
|
+
import { OnConflictNode } from '../operation-node/on-conflict-node.js';
|
|
2
|
+
import { OperationNodeSource } from '../operation-node/operation-node-source.js';
|
|
3
|
+
import { ComplexExpression } from '../parser/complex-expression-parser.js';
|
|
4
|
+
import { WhereGrouper, FilterOperator, FilterValueExpressionOrList } from '../parser/filter-parser.js';
|
|
5
|
+
import { ParseContext } from '../parser/parse-context.js';
|
|
6
|
+
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
7
|
+
import { MutationObject } from '../parser/update-set-parser.js';
|
|
8
|
+
import { AnyColumn, AnyRawBuilder } from '../util/type-utils.js';
|
|
9
|
+
import { WhereInterface } from './where-interface.js';
|
|
10
|
+
export declare class OnConflictBuilder<DB, TB extends keyof DB> implements WhereInterface<DB, TB> {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(props: OnConflictBuilderProps);
|
|
13
|
+
/**
|
|
14
|
+
* Specify a single column as the conflict target.
|
|
15
|
+
*
|
|
16
|
+
* Also see the {@link columns}, {@link constraint} and {@link expression}
|
|
17
|
+
* methods for alternative ways to specify the conflict target.
|
|
18
|
+
*/
|
|
19
|
+
column(column: AnyColumn<DB, TB>): OnConflictBuilder<DB, TB>;
|
|
20
|
+
/**
|
|
21
|
+
* Specify a list of columns as the conflict target.
|
|
22
|
+
*
|
|
23
|
+
* Also see the {@link column}, {@link constraint} and {@link expression}
|
|
24
|
+
* methods for alternative ways to specify the conflict target.
|
|
25
|
+
*/
|
|
26
|
+
columns(columns: ReadonlyArray<AnyColumn<DB, TB>>): OnConflictBuilder<DB, TB>;
|
|
27
|
+
/**
|
|
28
|
+
* Specify a specific constraint by name as the conflict target.
|
|
29
|
+
*
|
|
30
|
+
* Also see the {@link column}, {@link columns} and {@link expression}
|
|
31
|
+
* methods for alternative ways to specify the conflict target.
|
|
32
|
+
*/
|
|
33
|
+
constraint(constraintName: string): OnConflictBuilder<DB, TB>;
|
|
34
|
+
/**
|
|
35
|
+
* Specify an expression as the conflict target.
|
|
36
|
+
*
|
|
37
|
+
* This can be used if the unique index is an expression index.
|
|
38
|
+
*
|
|
39
|
+
* Also see the {@link column}, {@link columns} and {@link constraint}
|
|
40
|
+
* methods for alternative ways to specify the conflict target.
|
|
41
|
+
*/
|
|
42
|
+
expression(expression: AnyRawBuilder): OnConflictBuilder<DB, TB>;
|
|
43
|
+
/**
|
|
44
|
+
* Specify an index predicate for the index target.
|
|
45
|
+
*
|
|
46
|
+
* See {@link WhereInterface.where} for more info.
|
|
47
|
+
*/
|
|
48
|
+
where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): OnConflictBuilder<DB, TB>;
|
|
49
|
+
/**
|
|
50
|
+
* Adds a `where` clause to the query.
|
|
51
|
+
*
|
|
52
|
+
* Also see {@link orWhere}, {@link whereExists} and {@link whereRef}.
|
|
53
|
+
*
|
|
54
|
+
* ### Examples
|
|
55
|
+
*
|
|
56
|
+
* Find a row by column value:
|
|
57
|
+
*
|
|
58
|
+
* ```ts
|
|
59
|
+
* const person = await db
|
|
60
|
+
* .selectFrom('person')
|
|
61
|
+
* .selectAll()
|
|
62
|
+
* .where('id', '=', 100)
|
|
63
|
+
* .executeTakeFirst()
|
|
64
|
+
* ```
|
|
65
|
+
*
|
|
66
|
+
* The generated SQL (PostgreSQL):
|
|
67
|
+
*
|
|
68
|
+
* ```sql
|
|
69
|
+
* select * from "person" where "id" = $1
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* Operator can be any supported operator or if the typings don't support it
|
|
73
|
+
* you can always use `db.raw('your operator')`.
|
|
74
|
+
*
|
|
75
|
+
* ```ts
|
|
76
|
+
* const persons = await db
|
|
77
|
+
* .selectFrom('person')
|
|
78
|
+
* .selectAll()
|
|
79
|
+
* .where('id', '>', 100)
|
|
80
|
+
* .execute()
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* The generated SQL (PostgreSQL):
|
|
84
|
+
*
|
|
85
|
+
* ```sql
|
|
86
|
+
* select * from "person" where "id" > $1
|
|
87
|
+
* ```
|
|
88
|
+
*
|
|
89
|
+
* The `where` methods don't change the type of the query. You can add
|
|
90
|
+
* conditional `where`s easily by doing something like this:
|
|
91
|
+
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* let query = db
|
|
94
|
+
* .selectFrom('person')
|
|
95
|
+
* .selectAll()
|
|
96
|
+
*
|
|
97
|
+
* if (firstName) {
|
|
98
|
+
* query = query.where('first_name', '=', firstName)
|
|
99
|
+
* }
|
|
100
|
+
*
|
|
101
|
+
* const persons = await query.execute()
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* This is true for basically all methods execpt the `select` and
|
|
105
|
+
* `returning` methods, which DO change the return type of the
|
|
106
|
+
* query.
|
|
107
|
+
*
|
|
108
|
+
* Both the first and third argument can also be subqueries.
|
|
109
|
+
* A subquery is defined by passing a function and calling
|
|
110
|
+
* the `selectFrom` method of the object passed into the
|
|
111
|
+
* function:
|
|
112
|
+
*
|
|
113
|
+
* ```ts
|
|
114
|
+
* const persons = await db
|
|
115
|
+
* .selectFrom('person')
|
|
116
|
+
* .selectAll()
|
|
117
|
+
* .where(
|
|
118
|
+
* (qb) => qb.selectFrom('pet')
|
|
119
|
+
* .select('pet.name')
|
|
120
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
121
|
+
* .limit(1),
|
|
122
|
+
* '=',
|
|
123
|
+
* 'Fluffy'
|
|
124
|
+
* )
|
|
125
|
+
* .execute()
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* The generated SQL (PostgreSQL):
|
|
129
|
+
*
|
|
130
|
+
* ```sql
|
|
131
|
+
* select *
|
|
132
|
+
* from "person"
|
|
133
|
+
* where (
|
|
134
|
+
* select "pet"."name"
|
|
135
|
+
* from "pet"
|
|
136
|
+
* where "pet"."owner_id" = "person"."id"
|
|
137
|
+
* limit $1
|
|
138
|
+
* ) = $2
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* A `where in` query can be built by using the `in` operator and an array
|
|
142
|
+
* of values. The values in the array can also be subqueries or raw
|
|
143
|
+
* instances.
|
|
144
|
+
*
|
|
145
|
+
* ```ts
|
|
146
|
+
* const persons = await db
|
|
147
|
+
* .selectFrom('person')
|
|
148
|
+
* .selectAll()
|
|
149
|
+
* .where('person.id', 'in', [100, 200, 300])
|
|
150
|
+
* .execute()
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* The generated SQL (PostgreSQL):
|
|
154
|
+
*
|
|
155
|
+
* ```sql
|
|
156
|
+
* select * from "person" where "id" in ($1, $2, $3)
|
|
157
|
+
* ```
|
|
158
|
+
*
|
|
159
|
+
* If everything else fails, you can always pass {@link Kysely.raw | raw}
|
|
160
|
+
* as any of the arguments, including the operator:
|
|
161
|
+
*
|
|
162
|
+
* ```ts
|
|
163
|
+
* const persons = await db
|
|
164
|
+
* .selectFrom('person')
|
|
165
|
+
* .selectAll()
|
|
166
|
+
* .where(
|
|
167
|
+
* db.raw('coalesce(first_name, last_name)'),
|
|
168
|
+
* 'like',
|
|
169
|
+
* '%' + name + '%',
|
|
170
|
+
* )
|
|
171
|
+
* .execute()
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* The generated SQL (PostgreSQL):
|
|
175
|
+
*
|
|
176
|
+
* ```sql
|
|
177
|
+
* select * from "person"
|
|
178
|
+
* where coalesce(first_name, last_name) like $1
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* If you only pass one function argument to this method, it can be
|
|
182
|
+
* used to create parentheses around other where statements:
|
|
183
|
+
*
|
|
184
|
+
* ```ts
|
|
185
|
+
* const persons = await db
|
|
186
|
+
* .selectFrom('person')
|
|
187
|
+
* .selectAll()
|
|
188
|
+
* .where((qb) => qb
|
|
189
|
+
* .where('id', '=', 1)
|
|
190
|
+
* .orWhere('id', '=', 2)
|
|
191
|
+
* )
|
|
192
|
+
* .execute()
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* The generated SQL (PostgreSQL):
|
|
196
|
+
*
|
|
197
|
+
* ```sql
|
|
198
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* In all examples above the columns were known at compile time
|
|
202
|
+
* (except for the `raw` expressions). By default kysely only allows
|
|
203
|
+
* you to refer to columns that exist in the database **and** can be
|
|
204
|
+
* referred to in the current query and context.
|
|
205
|
+
*
|
|
206
|
+
* Sometimes you may want to refer to columns that come from the user
|
|
207
|
+
* input and thus are not available at compile time.
|
|
208
|
+
*
|
|
209
|
+
* You have two options, `db.raw` or `db.dynamic`. The example below
|
|
210
|
+
* uses both:
|
|
211
|
+
*
|
|
212
|
+
* ```ts
|
|
213
|
+
* const { ref } = db.dynamic
|
|
214
|
+
*
|
|
215
|
+
* const persons = await db
|
|
216
|
+
* .selectFrom('person')
|
|
217
|
+
* .selectAll()
|
|
218
|
+
* .where(ref(columnFromUserInput), '=', 1)
|
|
219
|
+
* .orWhere(db.raw('??', [columnFromUserInput]), '=', 2)
|
|
220
|
+
* .execute()
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
where(grouper: WhereGrouper<DB, TB>): OnConflictBuilder<DB, TB>;
|
|
224
|
+
where(raw: AnyRawBuilder): OnConflictBuilder<DB, TB>;
|
|
225
|
+
/**
|
|
226
|
+
* Specify an index predicate for the index target.
|
|
227
|
+
*
|
|
228
|
+
* See {@link WhereInterface.whereRef} for more info.
|
|
229
|
+
*/
|
|
230
|
+
whereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): OnConflictBuilder<DB, TB>;
|
|
231
|
+
/**
|
|
232
|
+
* Specify an index predicate for the index target.
|
|
233
|
+
*
|
|
234
|
+
* See {@link WhereInterface.orWhere} for more info.
|
|
235
|
+
*/
|
|
236
|
+
orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): OnConflictBuilder<DB, TB>;
|
|
237
|
+
/**
|
|
238
|
+
* Adds an `or where` clause to the query. Otherwise works just like {@link where}.
|
|
239
|
+
*
|
|
240
|
+
* It's often necessary to wrap `or where` clauses in parentheses to control
|
|
241
|
+
* precendence. You can use the one argument version of the `where` method
|
|
242
|
+
* for that. See the examples.
|
|
243
|
+
*
|
|
244
|
+
* ### Examples
|
|
245
|
+
*
|
|
246
|
+
* ```ts
|
|
247
|
+
* const persons = await db
|
|
248
|
+
* .selectFrom('person')
|
|
249
|
+
* .selectAll()
|
|
250
|
+
* .where('id', '=', 1)
|
|
251
|
+
* .orWhere('id', '=', 2)
|
|
252
|
+
* .execute()
|
|
253
|
+
* ```
|
|
254
|
+
*
|
|
255
|
+
* The generated SQL (PostgreSQL):
|
|
256
|
+
*
|
|
257
|
+
* ```sql
|
|
258
|
+
* select * from "person" where "id" = 1 or "id" = 2
|
|
259
|
+
* ```
|
|
260
|
+
*
|
|
261
|
+
* Grouping with parentheses:
|
|
262
|
+
*
|
|
263
|
+
* ```ts
|
|
264
|
+
* const persons = await db
|
|
265
|
+
* .selectFrom('person')
|
|
266
|
+
* .selectAll()
|
|
267
|
+
* .where((qb) => qb
|
|
268
|
+
* .where('id', '=', 1)
|
|
269
|
+
* .orWhere('id', '=', 2)
|
|
270
|
+
* )
|
|
271
|
+
* .execute()
|
|
272
|
+
* ```
|
|
273
|
+
*
|
|
274
|
+
* The generated SQL (PostgreSQL):
|
|
275
|
+
*
|
|
276
|
+
* ```sql
|
|
277
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
278
|
+
* ```
|
|
279
|
+
*
|
|
280
|
+
* Even the first `where` can be an `orWhere`. This is useful
|
|
281
|
+
* if you are looping through a set of conditions:
|
|
282
|
+
*
|
|
283
|
+
* ```ts
|
|
284
|
+
* const persons = await db
|
|
285
|
+
* .selectFrom('person')
|
|
286
|
+
* .selectAll()
|
|
287
|
+
* .where((qb) => qb
|
|
288
|
+
* .orWhere('id', '=', 1)
|
|
289
|
+
* .orWhere('id', '=', 2)
|
|
290
|
+
* )
|
|
291
|
+
* .execute()
|
|
292
|
+
* ```
|
|
293
|
+
*
|
|
294
|
+
* The generated SQL (PostgreSQL):
|
|
295
|
+
*
|
|
296
|
+
* ```sql
|
|
297
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
orWhere(grouper: WhereGrouper<DB, TB>): OnConflictBuilder<DB, TB>;
|
|
301
|
+
orWhere(raw: AnyRawBuilder): OnConflictBuilder<DB, TB>;
|
|
302
|
+
/**
|
|
303
|
+
* Specify an index predicate for the index target.
|
|
304
|
+
*
|
|
305
|
+
* See {@link WhereInterface.orWhereRef} for more info.
|
|
306
|
+
*/
|
|
307
|
+
orWhereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): OnConflictBuilder<DB, TB>;
|
|
308
|
+
/**
|
|
309
|
+
* Specify an index predicate for the index target.
|
|
310
|
+
*
|
|
311
|
+
* See {@link WhereInterface.whereExists} for more info.
|
|
312
|
+
*/
|
|
313
|
+
whereExists(arg: ComplexExpression<DB, TB>): OnConflictBuilder<DB, TB>;
|
|
314
|
+
/**
|
|
315
|
+
* Specify an index predicate for the index target.
|
|
316
|
+
*
|
|
317
|
+
* See {@link WhereInterface.whereNotExists} for more info.
|
|
318
|
+
*/
|
|
319
|
+
whereNotExists(arg: ComplexExpression<DB, TB>): OnConflictBuilder<DB, TB>;
|
|
320
|
+
/**
|
|
321
|
+
* Specify an index predicate for the index target.
|
|
322
|
+
*
|
|
323
|
+
* See {@link WhereInterface.orWhereExists} for more info.
|
|
324
|
+
*/
|
|
325
|
+
orWhereExists(arg: ComplexExpression<DB, TB>): OnConflictBuilder<DB, TB>;
|
|
326
|
+
/**
|
|
327
|
+
* Specify an index predicate for the index target.
|
|
328
|
+
*
|
|
329
|
+
* See {@link WhereInterface.orWhereNotExists} for more info.
|
|
330
|
+
*/
|
|
331
|
+
orWhereNotExists(arg: ComplexExpression<DB, TB>): OnConflictBuilder<DB, TB>;
|
|
332
|
+
/**
|
|
333
|
+
* Adds the "do nothing" conflict action.
|
|
334
|
+
*
|
|
335
|
+
* ### Examples
|
|
336
|
+
*
|
|
337
|
+
* ```ts
|
|
338
|
+
* await db
|
|
339
|
+
* .insertInto('person')
|
|
340
|
+
* .values({ first_name, pic })
|
|
341
|
+
* .onConflict((oc) => oc
|
|
342
|
+
* .column('pic')
|
|
343
|
+
* .doNothing()
|
|
344
|
+
* )
|
|
345
|
+
* ```
|
|
346
|
+
*
|
|
347
|
+
* The generated SQL (PostgreSQL):
|
|
348
|
+
*
|
|
349
|
+
* ```sql
|
|
350
|
+
* insert into "person" ("first_name", "pic")
|
|
351
|
+
* values ($1, $2)
|
|
352
|
+
* on conflict ("pic") do nothing
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
doNothing(): OnConflictDoNothingBuilder<DB, TB>;
|
|
356
|
+
/**
|
|
357
|
+
* Adds the "do update set" conflict action.
|
|
358
|
+
*
|
|
359
|
+
* ### Examples
|
|
360
|
+
*
|
|
361
|
+
* ```ts
|
|
362
|
+
* await db
|
|
363
|
+
* .insertInto('person')
|
|
364
|
+
* .values({ first_name, pic })
|
|
365
|
+
* .onConflict((oc) => oc
|
|
366
|
+
* .column('pic')
|
|
367
|
+
* .doUpdateSet({ first_name })
|
|
368
|
+
* )
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* The generated SQL (PostgreSQL):
|
|
372
|
+
*
|
|
373
|
+
* ```sql
|
|
374
|
+
* insert into "person" ("first_name", "pic")
|
|
375
|
+
* values ($1, $2)
|
|
376
|
+
* on conflict ("pic")
|
|
377
|
+
* do update set "first_name" = $3
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
doUpdateSet(updates: MutationObject<DB, TB>): OnConflictUpdateBuilder<{
|
|
381
|
+
[K in keyof DB | 'excluded']: K extends keyof DB ? DB[K] : DB[TB];
|
|
382
|
+
}, TB | 'excluded'>;
|
|
383
|
+
}
|
|
384
|
+
export interface OnConflictBuilderProps {
|
|
385
|
+
readonly onConflictNode: OnConflictNode;
|
|
386
|
+
readonly parseContext: ParseContext;
|
|
387
|
+
}
|
|
388
|
+
export declare class OnConflictDoNothingBuilder<DB, TB extends keyof DB> implements OperationNodeSource {
|
|
389
|
+
#private;
|
|
390
|
+
constructor(props: OnConflictBuilderProps);
|
|
391
|
+
toOperationNode(): OnConflictNode;
|
|
392
|
+
}
|
|
393
|
+
export declare class OnConflictUpdateBuilder<DB, TB extends keyof DB> implements WhereInterface<DB, TB>, OperationNodeSource {
|
|
394
|
+
#private;
|
|
395
|
+
constructor(props: OnConflictBuilderProps);
|
|
396
|
+
/**
|
|
397
|
+
* Specify a where condition for the update operation.
|
|
398
|
+
*
|
|
399
|
+
* See {@link WhereInterface.where} for more info.
|
|
400
|
+
*/
|
|
401
|
+
where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): OnConflictUpdateBuilder<DB, TB>;
|
|
402
|
+
/**
|
|
403
|
+
* Adds a `where` clause to the query.
|
|
404
|
+
*
|
|
405
|
+
* Also see {@link orWhere}, {@link whereExists} and {@link whereRef}.
|
|
406
|
+
*
|
|
407
|
+
* ### Examples
|
|
408
|
+
*
|
|
409
|
+
* Find a row by column value:
|
|
410
|
+
*
|
|
411
|
+
* ```ts
|
|
412
|
+
* const person = await db
|
|
413
|
+
* .selectFrom('person')
|
|
414
|
+
* .selectAll()
|
|
415
|
+
* .where('id', '=', 100)
|
|
416
|
+
* .executeTakeFirst()
|
|
417
|
+
* ```
|
|
418
|
+
*
|
|
419
|
+
* The generated SQL (PostgreSQL):
|
|
420
|
+
*
|
|
421
|
+
* ```sql
|
|
422
|
+
* select * from "person" where "id" = $1
|
|
423
|
+
* ```
|
|
424
|
+
*
|
|
425
|
+
* Operator can be any supported operator or if the typings don't support it
|
|
426
|
+
* you can always use `db.raw('your operator')`.
|
|
427
|
+
*
|
|
428
|
+
* ```ts
|
|
429
|
+
* const persons = await db
|
|
430
|
+
* .selectFrom('person')
|
|
431
|
+
* .selectAll()
|
|
432
|
+
* .where('id', '>', 100)
|
|
433
|
+
* .execute()
|
|
434
|
+
* ```
|
|
435
|
+
*
|
|
436
|
+
* The generated SQL (PostgreSQL):
|
|
437
|
+
*
|
|
438
|
+
* ```sql
|
|
439
|
+
* select * from "person" where "id" > $1
|
|
440
|
+
* ```
|
|
441
|
+
*
|
|
442
|
+
* The `where` methods don't change the type of the query. You can add
|
|
443
|
+
* conditional `where`s easily by doing something like this:
|
|
444
|
+
*
|
|
445
|
+
* ```ts
|
|
446
|
+
* let query = db
|
|
447
|
+
* .selectFrom('person')
|
|
448
|
+
* .selectAll()
|
|
449
|
+
*
|
|
450
|
+
* if (firstName) {
|
|
451
|
+
* query = query.where('first_name', '=', firstName)
|
|
452
|
+
* }
|
|
453
|
+
*
|
|
454
|
+
* const persons = await query.execute()
|
|
455
|
+
* ```
|
|
456
|
+
*
|
|
457
|
+
* This is true for basically all methods execpt the `select` and
|
|
458
|
+
* `returning` methods, which DO change the return type of the
|
|
459
|
+
* query.
|
|
460
|
+
*
|
|
461
|
+
* Both the first and third argument can also be subqueries.
|
|
462
|
+
* A subquery is defined by passing a function and calling
|
|
463
|
+
* the `selectFrom` method of the object passed into the
|
|
464
|
+
* function:
|
|
465
|
+
*
|
|
466
|
+
* ```ts
|
|
467
|
+
* const persons = await db
|
|
468
|
+
* .selectFrom('person')
|
|
469
|
+
* .selectAll()
|
|
470
|
+
* .where(
|
|
471
|
+
* (qb) => qb.selectFrom('pet')
|
|
472
|
+
* .select('pet.name')
|
|
473
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
474
|
+
* .limit(1),
|
|
475
|
+
* '=',
|
|
476
|
+
* 'Fluffy'
|
|
477
|
+
* )
|
|
478
|
+
* .execute()
|
|
479
|
+
* ```
|
|
480
|
+
*
|
|
481
|
+
* The generated SQL (PostgreSQL):
|
|
482
|
+
*
|
|
483
|
+
* ```sql
|
|
484
|
+
* select *
|
|
485
|
+
* from "person"
|
|
486
|
+
* where (
|
|
487
|
+
* select "pet"."name"
|
|
488
|
+
* from "pet"
|
|
489
|
+
* where "pet"."owner_id" = "person"."id"
|
|
490
|
+
* limit $1
|
|
491
|
+
* ) = $2
|
|
492
|
+
* ```
|
|
493
|
+
*
|
|
494
|
+
* A `where in` query can be built by using the `in` operator and an array
|
|
495
|
+
* of values. The values in the array can also be subqueries or raw
|
|
496
|
+
* instances.
|
|
497
|
+
*
|
|
498
|
+
* ```ts
|
|
499
|
+
* const persons = await db
|
|
500
|
+
* .selectFrom('person')
|
|
501
|
+
* .selectAll()
|
|
502
|
+
* .where('person.id', 'in', [100, 200, 300])
|
|
503
|
+
* .execute()
|
|
504
|
+
* ```
|
|
505
|
+
*
|
|
506
|
+
* The generated SQL (PostgreSQL):
|
|
507
|
+
*
|
|
508
|
+
* ```sql
|
|
509
|
+
* select * from "person" where "id" in ($1, $2, $3)
|
|
510
|
+
* ```
|
|
511
|
+
*
|
|
512
|
+
* If everything else fails, you can always pass {@link Kysely.raw | raw}
|
|
513
|
+
* as any of the arguments, including the operator:
|
|
514
|
+
*
|
|
515
|
+
* ```ts
|
|
516
|
+
* const persons = await db
|
|
517
|
+
* .selectFrom('person')
|
|
518
|
+
* .selectAll()
|
|
519
|
+
* .where(
|
|
520
|
+
* db.raw('coalesce(first_name, last_name)'),
|
|
521
|
+
* 'like',
|
|
522
|
+
* '%' + name + '%',
|
|
523
|
+
* )
|
|
524
|
+
* .execute()
|
|
525
|
+
* ```
|
|
526
|
+
*
|
|
527
|
+
* The generated SQL (PostgreSQL):
|
|
528
|
+
*
|
|
529
|
+
* ```sql
|
|
530
|
+
* select * from "person"
|
|
531
|
+
* where coalesce(first_name, last_name) like $1
|
|
532
|
+
* ```
|
|
533
|
+
*
|
|
534
|
+
* If you only pass one function argument to this method, it can be
|
|
535
|
+
* used to create parentheses around other where statements:
|
|
536
|
+
*
|
|
537
|
+
* ```ts
|
|
538
|
+
* const persons = await db
|
|
539
|
+
* .selectFrom('person')
|
|
540
|
+
* .selectAll()
|
|
541
|
+
* .where((qb) => qb
|
|
542
|
+
* .where('id', '=', 1)
|
|
543
|
+
* .orWhere('id', '=', 2)
|
|
544
|
+
* )
|
|
545
|
+
* .execute()
|
|
546
|
+
* ```
|
|
547
|
+
*
|
|
548
|
+
* The generated SQL (PostgreSQL):
|
|
549
|
+
*
|
|
550
|
+
* ```sql
|
|
551
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
552
|
+
* ```
|
|
553
|
+
*
|
|
554
|
+
* In all examples above the columns were known at compile time
|
|
555
|
+
* (except for the `raw` expressions). By default kysely only allows
|
|
556
|
+
* you to refer to columns that exist in the database **and** can be
|
|
557
|
+
* referred to in the current query and context.
|
|
558
|
+
*
|
|
559
|
+
* Sometimes you may want to refer to columns that come from the user
|
|
560
|
+
* input and thus are not available at compile time.
|
|
561
|
+
*
|
|
562
|
+
* You have two options, `db.raw` or `db.dynamic`. The example below
|
|
563
|
+
* uses both:
|
|
564
|
+
*
|
|
565
|
+
* ```ts
|
|
566
|
+
* const { ref } = db.dynamic
|
|
567
|
+
*
|
|
568
|
+
* const persons = await db
|
|
569
|
+
* .selectFrom('person')
|
|
570
|
+
* .selectAll()
|
|
571
|
+
* .where(ref(columnFromUserInput), '=', 1)
|
|
572
|
+
* .orWhere(db.raw('??', [columnFromUserInput]), '=', 2)
|
|
573
|
+
* .execute()
|
|
574
|
+
* ```
|
|
575
|
+
*/
|
|
576
|
+
where(grouper: WhereGrouper<DB, TB>): OnConflictUpdateBuilder<DB, TB>;
|
|
577
|
+
where(raw: AnyRawBuilder): OnConflictUpdateBuilder<DB, TB>;
|
|
578
|
+
/**
|
|
579
|
+
* Specify a where condition for the update operation.
|
|
580
|
+
*
|
|
581
|
+
* See {@link WhereInterface.whereRef} for more info.
|
|
582
|
+
*/
|
|
583
|
+
whereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): OnConflictUpdateBuilder<DB, TB>;
|
|
584
|
+
/**
|
|
585
|
+
* Specify a where condition for the update operation.
|
|
586
|
+
*
|
|
587
|
+
* See {@link WhereInterface.orWhere} for more info.
|
|
588
|
+
*/
|
|
589
|
+
orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): OnConflictUpdateBuilder<DB, TB>;
|
|
590
|
+
/**
|
|
591
|
+
* Adds an `or where` clause to the query. Otherwise works just like {@link where}.
|
|
592
|
+
*
|
|
593
|
+
* It's often necessary to wrap `or where` clauses in parentheses to control
|
|
594
|
+
* precendence. You can use the one argument version of the `where` method
|
|
595
|
+
* for that. See the examples.
|
|
596
|
+
*
|
|
597
|
+
* ### Examples
|
|
598
|
+
*
|
|
599
|
+
* ```ts
|
|
600
|
+
* const persons = await db
|
|
601
|
+
* .selectFrom('person')
|
|
602
|
+
* .selectAll()
|
|
603
|
+
* .where('id', '=', 1)
|
|
604
|
+
* .orWhere('id', '=', 2)
|
|
605
|
+
* .execute()
|
|
606
|
+
* ```
|
|
607
|
+
*
|
|
608
|
+
* The generated SQL (PostgreSQL):
|
|
609
|
+
*
|
|
610
|
+
* ```sql
|
|
611
|
+
* select * from "person" where "id" = 1 or "id" = 2
|
|
612
|
+
* ```
|
|
613
|
+
*
|
|
614
|
+
* Grouping with parentheses:
|
|
615
|
+
*
|
|
616
|
+
* ```ts
|
|
617
|
+
* const persons = await db
|
|
618
|
+
* .selectFrom('person')
|
|
619
|
+
* .selectAll()
|
|
620
|
+
* .where((qb) => qb
|
|
621
|
+
* .where('id', '=', 1)
|
|
622
|
+
* .orWhere('id', '=', 2)
|
|
623
|
+
* )
|
|
624
|
+
* .execute()
|
|
625
|
+
* ```
|
|
626
|
+
*
|
|
627
|
+
* The generated SQL (PostgreSQL):
|
|
628
|
+
*
|
|
629
|
+
* ```sql
|
|
630
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
631
|
+
* ```
|
|
632
|
+
*
|
|
633
|
+
* Even the first `where` can be an `orWhere`. This is useful
|
|
634
|
+
* if you are looping through a set of conditions:
|
|
635
|
+
*
|
|
636
|
+
* ```ts
|
|
637
|
+
* const persons = await db
|
|
638
|
+
* .selectFrom('person')
|
|
639
|
+
* .selectAll()
|
|
640
|
+
* .where((qb) => qb
|
|
641
|
+
* .orWhere('id', '=', 1)
|
|
642
|
+
* .orWhere('id', '=', 2)
|
|
643
|
+
* )
|
|
644
|
+
* .execute()
|
|
645
|
+
* ```
|
|
646
|
+
*
|
|
647
|
+
* The generated SQL (PostgreSQL):
|
|
648
|
+
*
|
|
649
|
+
* ```sql
|
|
650
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
653
|
+
orWhere(grouper: WhereGrouper<DB, TB>): OnConflictUpdateBuilder<DB, TB>;
|
|
654
|
+
orWhere(raw: AnyRawBuilder): OnConflictUpdateBuilder<DB, TB>;
|
|
655
|
+
/**
|
|
656
|
+
* Specify a where condition for the update operation.
|
|
657
|
+
*
|
|
658
|
+
* See {@link WhereInterface.orWhereRef} for more info.
|
|
659
|
+
*/
|
|
660
|
+
orWhereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): OnConflictUpdateBuilder<DB, TB>;
|
|
661
|
+
/**
|
|
662
|
+
* Specify a where condition for the update operation.
|
|
663
|
+
*
|
|
664
|
+
* See {@link WhereInterface.whereExists} for more info.
|
|
665
|
+
*/
|
|
666
|
+
whereExists(arg: ComplexExpression<DB, TB>): OnConflictUpdateBuilder<DB, TB>;
|
|
667
|
+
/**
|
|
668
|
+
* Specify a where condition for the update operation.
|
|
669
|
+
*
|
|
670
|
+
* See {@link WhereInterface.whereNotExists} for more info.
|
|
671
|
+
*/
|
|
672
|
+
whereNotExists(arg: ComplexExpression<DB, TB>): OnConflictUpdateBuilder<DB, TB>;
|
|
673
|
+
/**
|
|
674
|
+
* Specify a where condition for the update operation.
|
|
675
|
+
*
|
|
676
|
+
* See {@link WhereInterface.orWhereExists} for more info.
|
|
677
|
+
*/
|
|
678
|
+
orWhereExists(arg: ComplexExpression<DB, TB>): OnConflictUpdateBuilder<DB, TB>;
|
|
679
|
+
/**
|
|
680
|
+
* Specify a where condition for the update operation.
|
|
681
|
+
*
|
|
682
|
+
* See {@link WhereInterface.orWhereNotExists} for more info.
|
|
683
|
+
*/
|
|
684
|
+
orWhereNotExists(arg: ComplexExpression<DB, TB>): OnConflictUpdateBuilder<DB, TB>;
|
|
685
|
+
toOperationNode(): OnConflictNode;
|
|
686
|
+
}
|