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,317 @@
|
|
|
1
|
+
import { ColumnNode } from '../operation-node/column-node.js';
|
|
2
|
+
import { IdentifierNode } from '../operation-node/identifier-node.js';
|
|
3
|
+
import { OnConflictNode } from '../operation-node/on-conflict-node.js';
|
|
4
|
+
import { parseWhereFilter, parseReferenceFilter, parseExistFilter, parseNotExistFilter, } from '../parser/filter-parser.js';
|
|
5
|
+
import { parseUpdateObject, } from '../parser/update-set-parser.js';
|
|
6
|
+
import { freeze } from '../util/object-utils.js';
|
|
7
|
+
import { preventAwait } from '../util/prevent-await.js';
|
|
8
|
+
export class OnConflictBuilder {
|
|
9
|
+
#props;
|
|
10
|
+
constructor(props) {
|
|
11
|
+
this.#props = freeze(props);
|
|
12
|
+
}
|
|
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) {
|
|
20
|
+
const columnNode = ColumnNode.create(column);
|
|
21
|
+
return new OnConflictBuilder({
|
|
22
|
+
...this.#props,
|
|
23
|
+
onConflictNode: OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
24
|
+
columns: this.#props.onConflictNode.columns
|
|
25
|
+
? freeze([...this.#props.onConflictNode.columns, columnNode])
|
|
26
|
+
: freeze([columnNode]),
|
|
27
|
+
}),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Specify a list of columns as the conflict target.
|
|
32
|
+
*
|
|
33
|
+
* Also see the {@link column}, {@link constraint} and {@link expression}
|
|
34
|
+
* methods for alternative ways to specify the conflict target.
|
|
35
|
+
*/
|
|
36
|
+
columns(columns) {
|
|
37
|
+
const columnNodes = columns.map(ColumnNode.create);
|
|
38
|
+
return new OnConflictBuilder({
|
|
39
|
+
...this.#props,
|
|
40
|
+
onConflictNode: OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
41
|
+
columns: this.#props.onConflictNode.columns
|
|
42
|
+
? freeze([...this.#props.onConflictNode.columns, ...columnNodes])
|
|
43
|
+
: freeze(columnNodes),
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Specify a specific constraint by name as the conflict target.
|
|
49
|
+
*
|
|
50
|
+
* Also see the {@link column}, {@link columns} and {@link expression}
|
|
51
|
+
* methods for alternative ways to specify the conflict target.
|
|
52
|
+
*/
|
|
53
|
+
constraint(constraintName) {
|
|
54
|
+
return new OnConflictBuilder({
|
|
55
|
+
...this.#props,
|
|
56
|
+
onConflictNode: OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
57
|
+
constraint: IdentifierNode.create(constraintName),
|
|
58
|
+
}),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Specify an expression as the conflict target.
|
|
63
|
+
*
|
|
64
|
+
* This can be used if the unique index is an expression index.
|
|
65
|
+
*
|
|
66
|
+
* Also see the {@link column}, {@link columns} and {@link constraint}
|
|
67
|
+
* methods for alternative ways to specify the conflict target.
|
|
68
|
+
*/
|
|
69
|
+
expression(expression) {
|
|
70
|
+
return new OnConflictBuilder({
|
|
71
|
+
...this.#props,
|
|
72
|
+
onConflictNode: OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
73
|
+
indexExpression: expression.toOperationNode(),
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
where(...args) {
|
|
78
|
+
return new OnConflictBuilder({
|
|
79
|
+
...this.#props,
|
|
80
|
+
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseWhereFilter(this.#props.parseContext, args)),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Specify an index predicate for the index target.
|
|
85
|
+
*
|
|
86
|
+
* See {@link WhereInterface.whereRef} for more info.
|
|
87
|
+
*/
|
|
88
|
+
whereRef(lhs, op, rhs) {
|
|
89
|
+
return new OnConflictBuilder({
|
|
90
|
+
...this.#props,
|
|
91
|
+
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseReferenceFilter(this.#props.parseContext, lhs, op, rhs)),
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
orWhere(...args) {
|
|
95
|
+
return new OnConflictBuilder({
|
|
96
|
+
...this.#props,
|
|
97
|
+
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseWhereFilter(this.#props.parseContext, args)),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Specify an index predicate for the index target.
|
|
102
|
+
*
|
|
103
|
+
* See {@link WhereInterface.orWhereRef} for more info.
|
|
104
|
+
*/
|
|
105
|
+
orWhereRef(lhs, op, rhs) {
|
|
106
|
+
return new OnConflictBuilder({
|
|
107
|
+
...this.#props,
|
|
108
|
+
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseReferenceFilter(this.#props.parseContext, lhs, op, rhs)),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Specify an index predicate for the index target.
|
|
113
|
+
*
|
|
114
|
+
* See {@link WhereInterface.whereExists} for more info.
|
|
115
|
+
*/
|
|
116
|
+
whereExists(arg) {
|
|
117
|
+
return new OnConflictBuilder({
|
|
118
|
+
...this.#props,
|
|
119
|
+
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseExistFilter(this.#props.parseContext, arg)),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Specify an index predicate for the index target.
|
|
124
|
+
*
|
|
125
|
+
* See {@link WhereInterface.whereNotExists} for more info.
|
|
126
|
+
*/
|
|
127
|
+
whereNotExists(arg) {
|
|
128
|
+
return new OnConflictBuilder({
|
|
129
|
+
...this.#props,
|
|
130
|
+
onConflictNode: OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, parseNotExistFilter(this.#props.parseContext, arg)),
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Specify an index predicate for the index target.
|
|
135
|
+
*
|
|
136
|
+
* See {@link WhereInterface.orWhereExists} for more info.
|
|
137
|
+
*/
|
|
138
|
+
orWhereExists(arg) {
|
|
139
|
+
return new OnConflictBuilder({
|
|
140
|
+
...this.#props,
|
|
141
|
+
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseExistFilter(this.#props.parseContext, arg)),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Specify an index predicate for the index target.
|
|
146
|
+
*
|
|
147
|
+
* See {@link WhereInterface.orWhereNotExists} for more info.
|
|
148
|
+
*/
|
|
149
|
+
orWhereNotExists(arg) {
|
|
150
|
+
return new OnConflictBuilder({
|
|
151
|
+
...this.#props,
|
|
152
|
+
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseNotExistFilter(this.#props.parseContext, arg)),
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Adds the "do nothing" conflict action.
|
|
157
|
+
*
|
|
158
|
+
* ### Examples
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* await db
|
|
162
|
+
* .insertInto('person')
|
|
163
|
+
* .values({ first_name, pic })
|
|
164
|
+
* .onConflict((oc) => oc
|
|
165
|
+
* .column('pic')
|
|
166
|
+
* .doNothing()
|
|
167
|
+
* )
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* The generated SQL (PostgreSQL):
|
|
171
|
+
*
|
|
172
|
+
* ```sql
|
|
173
|
+
* insert into "person" ("first_name", "pic")
|
|
174
|
+
* values ($1, $2)
|
|
175
|
+
* on conflict ("pic") do nothing
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
doNothing() {
|
|
179
|
+
return new OnConflictDoNothingBuilder({
|
|
180
|
+
...this.#props,
|
|
181
|
+
onConflictNode: OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
182
|
+
doNothing: true,
|
|
183
|
+
}),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Adds the "do update set" conflict action.
|
|
188
|
+
*
|
|
189
|
+
* ### Examples
|
|
190
|
+
*
|
|
191
|
+
* ```ts
|
|
192
|
+
* await db
|
|
193
|
+
* .insertInto('person')
|
|
194
|
+
* .values({ first_name, pic })
|
|
195
|
+
* .onConflict((oc) => oc
|
|
196
|
+
* .column('pic')
|
|
197
|
+
* .doUpdateSet({ first_name })
|
|
198
|
+
* )
|
|
199
|
+
* ```
|
|
200
|
+
*
|
|
201
|
+
* The generated SQL (PostgreSQL):
|
|
202
|
+
*
|
|
203
|
+
* ```sql
|
|
204
|
+
* insert into "person" ("first_name", "pic")
|
|
205
|
+
* values ($1, $2)
|
|
206
|
+
* on conflict ("pic")
|
|
207
|
+
* do update set "first_name" = $3
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
doUpdateSet(updates) {
|
|
211
|
+
return new OnConflictUpdateBuilder({
|
|
212
|
+
...this.#props,
|
|
213
|
+
onConflictNode: OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
214
|
+
updates: parseUpdateObject(this.#props.parseContext, updates),
|
|
215
|
+
}),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
preventAwait(OnConflictBuilder, "don't await OnConflictBuilder instances.");
|
|
220
|
+
export class OnConflictDoNothingBuilder {
|
|
221
|
+
#props;
|
|
222
|
+
constructor(props) {
|
|
223
|
+
this.#props = freeze(props);
|
|
224
|
+
}
|
|
225
|
+
toOperationNode() {
|
|
226
|
+
return this.#props.onConflictNode;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
preventAwait(OnConflictDoNothingBuilder, "don't await OnConflictDoNothingBuilder instances.");
|
|
230
|
+
export class OnConflictUpdateBuilder {
|
|
231
|
+
#props;
|
|
232
|
+
constructor(props) {
|
|
233
|
+
this.#props = freeze(props);
|
|
234
|
+
}
|
|
235
|
+
where(...args) {
|
|
236
|
+
return new OnConflictUpdateBuilder({
|
|
237
|
+
...this.#props,
|
|
238
|
+
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseWhereFilter(this.#props.parseContext, args)),
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Specify a where condition for the update operation.
|
|
243
|
+
*
|
|
244
|
+
* See {@link WhereInterface.whereRef} for more info.
|
|
245
|
+
*/
|
|
246
|
+
whereRef(lhs, op, rhs) {
|
|
247
|
+
return new OnConflictUpdateBuilder({
|
|
248
|
+
...this.#props,
|
|
249
|
+
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseReferenceFilter(this.#props.parseContext, lhs, op, rhs)),
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
orWhere(...args) {
|
|
253
|
+
return new OnConflictUpdateBuilder({
|
|
254
|
+
...this.#props,
|
|
255
|
+
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseWhereFilter(this.#props.parseContext, args)),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Specify a where condition for the update operation.
|
|
260
|
+
*
|
|
261
|
+
* See {@link WhereInterface.orWhereRef} for more info.
|
|
262
|
+
*/
|
|
263
|
+
orWhereRef(lhs, op, rhs) {
|
|
264
|
+
return new OnConflictUpdateBuilder({
|
|
265
|
+
...this.#props,
|
|
266
|
+
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseReferenceFilter(this.#props.parseContext, lhs, op, rhs)),
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Specify a where condition for the update operation.
|
|
271
|
+
*
|
|
272
|
+
* See {@link WhereInterface.whereExists} for more info.
|
|
273
|
+
*/
|
|
274
|
+
whereExists(arg) {
|
|
275
|
+
return new OnConflictUpdateBuilder({
|
|
276
|
+
...this.#props,
|
|
277
|
+
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseExistFilter(this.#props.parseContext, arg)),
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Specify a where condition for the update operation.
|
|
282
|
+
*
|
|
283
|
+
* See {@link WhereInterface.whereNotExists} for more info.
|
|
284
|
+
*/
|
|
285
|
+
whereNotExists(arg) {
|
|
286
|
+
return new OnConflictUpdateBuilder({
|
|
287
|
+
...this.#props,
|
|
288
|
+
onConflictNode: OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, parseNotExistFilter(this.#props.parseContext, arg)),
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Specify a where condition for the update operation.
|
|
293
|
+
*
|
|
294
|
+
* See {@link WhereInterface.orWhereExists} for more info.
|
|
295
|
+
*/
|
|
296
|
+
orWhereExists(arg) {
|
|
297
|
+
return new OnConflictUpdateBuilder({
|
|
298
|
+
...this.#props,
|
|
299
|
+
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseExistFilter(this.#props.parseContext, arg)),
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Specify a where condition for the update operation.
|
|
304
|
+
*
|
|
305
|
+
* See {@link WhereInterface.orWhereNotExists} for more info.
|
|
306
|
+
*/
|
|
307
|
+
orWhereNotExists(arg) {
|
|
308
|
+
return new OnConflictUpdateBuilder({
|
|
309
|
+
...this.#props,
|
|
310
|
+
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseNotExistFilter(this.#props.parseContext, arg)),
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
toOperationNode() {
|
|
314
|
+
return this.#props.onConflictNode;
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
preventAwait(OnConflictUpdateBuilder, "don't await OnConflictUpdateBuilder instances.");
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ReturningRow } from '../parser/returning-parser.js';
|
|
2
2
|
import { SelectExpression } from '../parser/select-parser.js';
|
|
3
|
+
import { Selectable } from '../util/column-type.js';
|
|
3
4
|
export interface ReturningInterface<DB, TB extends keyof DB, O> {
|
|
4
5
|
/**
|
|
5
6
|
* Allows you to return data from modified rows.
|
|
@@ -21,7 +22,6 @@ export interface ReturningInterface<DB, TB extends keyof DB, O> {
|
|
|
21
22
|
* const { id } = await db
|
|
22
23
|
* .insertInto('person')
|
|
23
24
|
* .values({
|
|
24
|
-
* id: db.generated,
|
|
25
25
|
* first_name: 'Jennifer',
|
|
26
26
|
* last_name: 'Aniston'
|
|
27
27
|
* })
|
|
@@ -35,7 +35,6 @@ export interface ReturningInterface<DB, TB extends keyof DB, O> {
|
|
|
35
35
|
* const { id, first_name } = await db
|
|
36
36
|
* .insertInto('person')
|
|
37
37
|
* .values({
|
|
38
|
-
* id: db.generated,
|
|
39
38
|
* first_name: 'Jennifer',
|
|
40
39
|
* last_name: 'Aniston'
|
|
41
40
|
* })
|
|
@@ -51,7 +50,6 @@ export interface ReturningInterface<DB, TB extends keyof DB, O> {
|
|
|
51
50
|
* const { id, full_name, first_pet_id } = await db
|
|
52
51
|
* .insertInto('person')
|
|
53
52
|
* .values({
|
|
54
|
-
* id: db.generated,
|
|
55
53
|
* first_name: 'Jennifer',
|
|
56
54
|
* last_name: 'Aniston'
|
|
57
55
|
* })
|
|
@@ -69,5 +67,5 @@ export interface ReturningInterface<DB, TB extends keyof DB, O> {
|
|
|
69
67
|
* Adds a `returning *` to an insert/update/delete query on databases
|
|
70
68
|
* that support `returning` such as PostgreSQL.
|
|
71
69
|
*/
|
|
72
|
-
returningAll(): ReturningInterface<DB, TB, DB[TB]
|
|
70
|
+
returningAll(): ReturningInterface<DB, TB, Selectable<DB[TB]>>;
|
|
73
71
|
}
|
|
@@ -731,7 +731,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
731
731
|
*/
|
|
732
732
|
selectAll<T extends TB>(table: ReadonlyArray<T>): SelectAllQueryBuilder<DB, TB, O, T>;
|
|
733
733
|
selectAll<T extends TB>(table: T): SelectAllQueryBuilder<DB, TB, O, T>;
|
|
734
|
-
selectAll
|
|
734
|
+
selectAll(): SelectAllQueryBuilder<DB, TB, O, TB>;
|
|
735
735
|
/**
|
|
736
736
|
* Joins another table to the query using an inner join.
|
|
737
737
|
*
|
|
@@ -18,6 +18,7 @@ import { WhereInterface } from './where-interface.js';
|
|
|
18
18
|
import { JoinInterface } from './join-interface.js';
|
|
19
19
|
import { ReturningInterface } from './returning-interface.js';
|
|
20
20
|
import { NoResultErrorConstructor } from './no-result-error.js';
|
|
21
|
+
import { Selectable } from '../util/column-type.js';
|
|
21
22
|
export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, JoinInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable {
|
|
22
23
|
#private;
|
|
23
24
|
constructor(props: UpdateQueryBuilderProps);
|
|
@@ -626,7 +627,6 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
626
627
|
* const { id } = await db
|
|
627
628
|
* .insertInto('person')
|
|
628
629
|
* .values({
|
|
629
|
-
* id: db.generated,
|
|
630
630
|
* first_name: 'Jennifer',
|
|
631
631
|
* last_name: 'Aniston'
|
|
632
632
|
* })
|
|
@@ -640,7 +640,6 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
640
640
|
* const { id, first_name } = await db
|
|
641
641
|
* .insertInto('person')
|
|
642
642
|
* .values({
|
|
643
|
-
* id: db.generated,
|
|
644
643
|
* first_name: 'Jennifer',
|
|
645
644
|
* last_name: 'Aniston'
|
|
646
645
|
* })
|
|
@@ -656,7 +655,6 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
656
655
|
* const { id, full_name, first_pet_id } = await db
|
|
657
656
|
* .insertInto('person')
|
|
658
657
|
* .values({
|
|
659
|
-
* id: db.generated,
|
|
660
658
|
* first_name: 'Jennifer',
|
|
661
659
|
* last_name: 'Aniston'
|
|
662
660
|
* })
|
|
@@ -674,7 +672,7 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
674
672
|
* Adds a `returning *` to an insert/update/delete query on databases
|
|
675
673
|
* that support `returning` such as PostgreSQL.
|
|
676
674
|
*/
|
|
677
|
-
returningAll(): UpdateQueryBuilder<DB, TB, DB[TB]
|
|
675
|
+
returningAll(): UpdateQueryBuilder<DB, TB, Selectable<DB[TB]>>;
|
|
678
676
|
/**
|
|
679
677
|
* Simply calls the given function passing `this` as the only argument.
|
|
680
678
|
*
|
|
@@ -64,7 +64,7 @@ import { ColumnNode } from '../operation-node/column-node.js';
|
|
|
64
64
|
import { UnionNode } from '../operation-node/union-node.js';
|
|
65
65
|
import { CreateViewNode } from '../operation-node/create-view-node.js';
|
|
66
66
|
import { DropViewNode } from '../operation-node/drop-view-node.js';
|
|
67
|
-
import {
|
|
67
|
+
import { GeneratedNode } from '../operation-node/generated-node.js';
|
|
68
68
|
import { DefaultValueNode } from '../operation-node/default-value-node.js';
|
|
69
69
|
import { OnNode } from '../operation-node/on-node.js';
|
|
70
70
|
import { ValuesNode } from '../operation-node/values-node.js';
|
|
@@ -142,7 +142,7 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
142
142
|
protected visitUnion(node: UnionNode): void;
|
|
143
143
|
protected visitCreateView(node: CreateViewNode): void;
|
|
144
144
|
protected visitDropView(node: DropViewNode): void;
|
|
145
|
-
protected
|
|
145
|
+
protected visitGenerated(node: GeneratedNode): void;
|
|
146
146
|
protected visitDefaultValue(node: DefaultValueNode): void;
|
|
147
147
|
protected append(str: string): void;
|
|
148
148
|
protected appendValue(parameter: unknown): void;
|
|
@@ -324,9 +324,9 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
324
324
|
if (node.unsigned) {
|
|
325
325
|
this.append(' unsigned');
|
|
326
326
|
}
|
|
327
|
-
if (node.
|
|
327
|
+
if (node.generated) {
|
|
328
328
|
this.append(' ');
|
|
329
|
-
this.visitNode(node.
|
|
329
|
+
this.visitNode(node.generated);
|
|
330
330
|
}
|
|
331
331
|
if (node.defaultTo) {
|
|
332
332
|
this.append(' ');
|
|
@@ -451,16 +451,29 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
451
451
|
this.compileList(node.columns);
|
|
452
452
|
this.append(')');
|
|
453
453
|
}
|
|
454
|
-
if (node.constraint) {
|
|
454
|
+
else if (node.constraint) {
|
|
455
455
|
this.append(' on constraint ');
|
|
456
456
|
this.visitNode(node.constraint);
|
|
457
457
|
}
|
|
458
|
+
else if (node.indexExpression) {
|
|
459
|
+
this.append(' (');
|
|
460
|
+
this.visitNode(node.indexExpression);
|
|
461
|
+
this.append(')');
|
|
462
|
+
}
|
|
463
|
+
if (node.indexWhere) {
|
|
464
|
+
this.append(' ');
|
|
465
|
+
this.visitNode(node.indexWhere);
|
|
466
|
+
}
|
|
458
467
|
if (node.doNothing === true) {
|
|
459
468
|
this.append(' do nothing');
|
|
460
469
|
}
|
|
461
470
|
else if (node.updates) {
|
|
462
471
|
this.append(' do update set ');
|
|
463
472
|
this.compileList(node.updates);
|
|
473
|
+
if (node.updateWhere) {
|
|
474
|
+
this.append(' ');
|
|
475
|
+
this.visitNode(node.updateWhere);
|
|
476
|
+
}
|
|
464
477
|
}
|
|
465
478
|
}
|
|
466
479
|
visitOnDuplicateKey(node) {
|
|
@@ -722,10 +735,23 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
722
735
|
}
|
|
723
736
|
this.visitNode(node.name);
|
|
724
737
|
}
|
|
725
|
-
|
|
726
|
-
this.append('generated
|
|
727
|
-
|
|
728
|
-
|
|
738
|
+
visitGenerated(node) {
|
|
739
|
+
this.append('generated ');
|
|
740
|
+
if (node.always) {
|
|
741
|
+
this.append('always ');
|
|
742
|
+
}
|
|
743
|
+
if (node.byDefault) {
|
|
744
|
+
this.append('by default ');
|
|
745
|
+
}
|
|
746
|
+
this.append('as ');
|
|
747
|
+
if (node.identity) {
|
|
748
|
+
this.append('identity');
|
|
749
|
+
}
|
|
750
|
+
if (node.expression) {
|
|
751
|
+
this.append('(');
|
|
752
|
+
this.visitNode(node.expression);
|
|
753
|
+
this.append(')');
|
|
754
|
+
}
|
|
729
755
|
if (node.stored) {
|
|
730
756
|
this.append(' stored');
|
|
731
757
|
}
|
|
@@ -137,7 +137,6 @@ export declare class QueryCreator<DB> {
|
|
|
137
137
|
* const result = await db
|
|
138
138
|
* .insertInto('person')
|
|
139
139
|
* .values({
|
|
140
|
-
* id: db.generated,
|
|
141
140
|
* first_name: 'Jennifer',
|
|
142
141
|
* last_name: 'Aniston'
|
|
143
142
|
* })
|
|
@@ -152,7 +151,6 @@ export declare class QueryCreator<DB> {
|
|
|
152
151
|
* const { id } = await db
|
|
153
152
|
* .insertInto('person')
|
|
154
153
|
* .values({
|
|
155
|
-
* id: db.generated,
|
|
156
154
|
* first_name: 'Jennifer',
|
|
157
155
|
* last_name: 'Aniston'
|
|
158
156
|
* })
|
|
@@ -43,7 +43,6 @@ export class QueryCreator {
|
|
|
43
43
|
* const result = await db
|
|
44
44
|
* .insertInto('person')
|
|
45
45
|
* .values({
|
|
46
|
-
* id: db.generated,
|
|
47
46
|
* first_name: 'Jennifer',
|
|
48
47
|
* last_name: 'Aniston'
|
|
49
48
|
* })
|
|
@@ -58,7 +57,6 @@ export class QueryCreator {
|
|
|
58
57
|
* const { id } = await db
|
|
59
58
|
* .insertInto('person')
|
|
60
59
|
* .values({
|
|
61
|
-
* id: db.generated,
|
|
62
60
|
* first_name: 'Jennifer',
|
|
63
61
|
* last_name: 'Aniston'
|
|
64
62
|
* })
|
|
@@ -31,7 +31,7 @@ export declare class AlterTableBuilder {
|
|
|
31
31
|
*/
|
|
32
32
|
modifyColumn(columnName: string, dataType: DataTypeExpression): AlterTableModifyColumnBuilder;
|
|
33
33
|
addUniqueConstraint(constraintName: string, columns: string[]): AlterTableExecutor;
|
|
34
|
-
addCheckConstraint(constraintName: string, checkExpression:
|
|
34
|
+
addCheckConstraint(constraintName: string, checkExpression: AnyRawBuilder): AlterTableExecutor;
|
|
35
35
|
addForeignKeyConstraint(constraintName: string, columns: string[], targetTable: string, targetColumns: string[]): AlterTableAddForeignKeyConstraintBuilder;
|
|
36
36
|
}
|
|
37
37
|
export interface AlterTableBuilderProps {
|
|
@@ -151,11 +151,13 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
151
151
|
* ```ts
|
|
152
152
|
* db.schema
|
|
153
153
|
* .createTable('pet')
|
|
154
|
-
* .addColumn('number_of_legs', 'integer', (col) =>
|
|
154
|
+
* .addColumn('number_of_legs', 'integer', (col) =>
|
|
155
|
+
* col.check(db.raw('number_of_legs < 5'))
|
|
156
|
+
* )
|
|
155
157
|
* .execute()
|
|
156
158
|
* ```
|
|
157
159
|
*/
|
|
158
|
-
check(
|
|
160
|
+
check(expression: AnyRawBuilder): AlterTableAddColumnBuilder;
|
|
159
161
|
/**
|
|
160
162
|
* Makes the column a generated column using a `generated always as` statement.
|
|
161
163
|
*
|
|
@@ -165,12 +167,20 @@ export declare class AlterTableAddColumnBuilder implements ColumnDefinitionBuild
|
|
|
165
167
|
* db.schema
|
|
166
168
|
* .createTable('person')
|
|
167
169
|
* .addColumn('full_name', 'varchar(255)',
|
|
168
|
-
* (col) => col.generatedAlwaysAs("concat(first_name, ' ', last_name)")
|
|
170
|
+
* (col) => col.generatedAlwaysAs(db.raw("concat(first_name, ' ', last_name)"))
|
|
169
171
|
* )
|
|
170
172
|
* .execute()
|
|
171
173
|
* ```
|
|
172
174
|
*/
|
|
173
|
-
generatedAlwaysAs(
|
|
175
|
+
generatedAlwaysAs(expression: AnyRawBuilder): AlterTableAddColumnBuilder;
|
|
176
|
+
/**
|
|
177
|
+
* Adds the `generated always as identity` specifier on supported dialects.
|
|
178
|
+
*/
|
|
179
|
+
generatedAlwaysAsIdentity(): AlterTableAddColumnBuilder;
|
|
180
|
+
/**
|
|
181
|
+
* Adds the `generated by default as identity` specifier on supported dialects.
|
|
182
|
+
*/
|
|
183
|
+
generatedByDefaultAsIdentity(): AlterTableAddColumnBuilder;
|
|
174
184
|
/**
|
|
175
185
|
* Makes a generated column stored instead of virtual. This method can only
|
|
176
186
|
* be used with {@link generatedAlwaysAs}
|
|
@@ -286,11 +296,13 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
|
|
|
286
296
|
* ```ts
|
|
287
297
|
* db.schema
|
|
288
298
|
* .createTable('pet')
|
|
289
|
-
* .addColumn('number_of_legs', 'integer', (col) =>
|
|
299
|
+
* .addColumn('number_of_legs', 'integer', (col) =>
|
|
300
|
+
* col.check(db.raw('number_of_legs < 5'))
|
|
301
|
+
* )
|
|
290
302
|
* .execute()
|
|
291
303
|
* ```
|
|
292
304
|
*/
|
|
293
|
-
check(
|
|
305
|
+
check(expression: AnyRawBuilder): AlterTableModifyColumnBuilder;
|
|
294
306
|
/**
|
|
295
307
|
* Makes the column a generated column using a `generated always as` statement.
|
|
296
308
|
*
|
|
@@ -300,12 +312,20 @@ export declare class AlterTableModifyColumnBuilder implements ColumnDefinitionBu
|
|
|
300
312
|
* db.schema
|
|
301
313
|
* .createTable('person')
|
|
302
314
|
* .addColumn('full_name', 'varchar(255)',
|
|
303
|
-
* (col) => col.generatedAlwaysAs("concat(first_name, ' ', last_name)")
|
|
315
|
+
* (col) => col.generatedAlwaysAs(db.raw("concat(first_name, ' ', last_name)"))
|
|
304
316
|
* )
|
|
305
317
|
* .execute()
|
|
306
318
|
* ```
|
|
307
319
|
*/
|
|
308
|
-
generatedAlwaysAs(
|
|
320
|
+
generatedAlwaysAs(expression: AnyRawBuilder): AlterTableModifyColumnBuilder;
|
|
321
|
+
/**
|
|
322
|
+
* Adds the `generated always as identity` specifier on supported dialects.
|
|
323
|
+
*/
|
|
324
|
+
generatedAlwaysAsIdentity(): AlterTableModifyColumnBuilder;
|
|
325
|
+
/**
|
|
326
|
+
* Adds the `generated by default as identity` specifier on supported dialects.
|
|
327
|
+
*/
|
|
328
|
+
generatedByDefaultAsIdentity(): AlterTableModifyColumnBuilder;
|
|
309
329
|
/**
|
|
310
330
|
* Makes a generated column stored instead of virtual. This method can only
|
|
311
331
|
* be used with {@link generatedAlwaysAs}
|