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,323 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OnConflictUpdateBuilder = exports.OnConflictDoNothingBuilder = exports.OnConflictBuilder = void 0;
|
|
4
|
+
const column_node_js_1 = require("../operation-node/column-node.js");
|
|
5
|
+
const identifier_node_js_1 = require("../operation-node/identifier-node.js");
|
|
6
|
+
const on_conflict_node_js_1 = require("../operation-node/on-conflict-node.js");
|
|
7
|
+
const filter_parser_js_1 = require("../parser/filter-parser.js");
|
|
8
|
+
const update_set_parser_js_1 = require("../parser/update-set-parser.js");
|
|
9
|
+
const object_utils_js_1 = require("../util/object-utils.js");
|
|
10
|
+
const prevent_await_js_1 = require("../util/prevent-await.js");
|
|
11
|
+
class OnConflictBuilder {
|
|
12
|
+
#props;
|
|
13
|
+
constructor(props) {
|
|
14
|
+
this.#props = (0, object_utils_js_1.freeze)(props);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Specify a single column as the conflict target.
|
|
18
|
+
*
|
|
19
|
+
* Also see the {@link columns}, {@link constraint} and {@link expression}
|
|
20
|
+
* methods for alternative ways to specify the conflict target.
|
|
21
|
+
*/
|
|
22
|
+
column(column) {
|
|
23
|
+
const columnNode = column_node_js_1.ColumnNode.create(column);
|
|
24
|
+
return new OnConflictBuilder({
|
|
25
|
+
...this.#props,
|
|
26
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
27
|
+
columns: this.#props.onConflictNode.columns
|
|
28
|
+
? (0, object_utils_js_1.freeze)([...this.#props.onConflictNode.columns, columnNode])
|
|
29
|
+
: (0, object_utils_js_1.freeze)([columnNode]),
|
|
30
|
+
}),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Specify a list of columns as the conflict target.
|
|
35
|
+
*
|
|
36
|
+
* Also see the {@link column}, {@link constraint} and {@link expression}
|
|
37
|
+
* methods for alternative ways to specify the conflict target.
|
|
38
|
+
*/
|
|
39
|
+
columns(columns) {
|
|
40
|
+
const columnNodes = columns.map(column_node_js_1.ColumnNode.create);
|
|
41
|
+
return new OnConflictBuilder({
|
|
42
|
+
...this.#props,
|
|
43
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
44
|
+
columns: this.#props.onConflictNode.columns
|
|
45
|
+
? (0, object_utils_js_1.freeze)([...this.#props.onConflictNode.columns, ...columnNodes])
|
|
46
|
+
: (0, object_utils_js_1.freeze)(columnNodes),
|
|
47
|
+
}),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Specify a specific constraint by name as the conflict target.
|
|
52
|
+
*
|
|
53
|
+
* Also see the {@link column}, {@link columns} and {@link expression}
|
|
54
|
+
* methods for alternative ways to specify the conflict target.
|
|
55
|
+
*/
|
|
56
|
+
constraint(constraintName) {
|
|
57
|
+
return new OnConflictBuilder({
|
|
58
|
+
...this.#props,
|
|
59
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
60
|
+
constraint: identifier_node_js_1.IdentifierNode.create(constraintName),
|
|
61
|
+
}),
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Specify an expression as the conflict target.
|
|
66
|
+
*
|
|
67
|
+
* This can be used if the unique index is an expression index.
|
|
68
|
+
*
|
|
69
|
+
* Also see the {@link column}, {@link columns} and {@link constraint}
|
|
70
|
+
* methods for alternative ways to specify the conflict target.
|
|
71
|
+
*/
|
|
72
|
+
expression(expression) {
|
|
73
|
+
return new OnConflictBuilder({
|
|
74
|
+
...this.#props,
|
|
75
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
76
|
+
indexExpression: expression.toOperationNode(),
|
|
77
|
+
}),
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
where(...args) {
|
|
81
|
+
return new OnConflictBuilder({
|
|
82
|
+
...this.#props,
|
|
83
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseWhereFilter)(this.#props.parseContext, args)),
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Specify an index predicate for the index target.
|
|
88
|
+
*
|
|
89
|
+
* See {@link WhereInterface.whereRef} for more info.
|
|
90
|
+
*/
|
|
91
|
+
whereRef(lhs, op, rhs) {
|
|
92
|
+
return new OnConflictBuilder({
|
|
93
|
+
...this.#props,
|
|
94
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
orWhere(...args) {
|
|
98
|
+
return new OnConflictBuilder({
|
|
99
|
+
...this.#props,
|
|
100
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseWhereFilter)(this.#props.parseContext, args)),
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Specify an index predicate for the index target.
|
|
105
|
+
*
|
|
106
|
+
* See {@link WhereInterface.orWhereRef} for more info.
|
|
107
|
+
*/
|
|
108
|
+
orWhereRef(lhs, op, rhs) {
|
|
109
|
+
return new OnConflictBuilder({
|
|
110
|
+
...this.#props,
|
|
111
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Specify an index predicate for the index target.
|
|
116
|
+
*
|
|
117
|
+
* See {@link WhereInterface.whereExists} for more info.
|
|
118
|
+
*/
|
|
119
|
+
whereExists(arg) {
|
|
120
|
+
return new OnConflictBuilder({
|
|
121
|
+
...this.#props,
|
|
122
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Specify an index predicate for the index target.
|
|
127
|
+
*
|
|
128
|
+
* See {@link WhereInterface.whereNotExists} for more info.
|
|
129
|
+
*/
|
|
130
|
+
whereNotExists(arg) {
|
|
131
|
+
return new OnConflictBuilder({
|
|
132
|
+
...this.#props,
|
|
133
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithIndexWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Specify an index predicate for the index target.
|
|
138
|
+
*
|
|
139
|
+
* See {@link WhereInterface.orWhereExists} for more info.
|
|
140
|
+
*/
|
|
141
|
+
orWhereExists(arg) {
|
|
142
|
+
return new OnConflictBuilder({
|
|
143
|
+
...this.#props,
|
|
144
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Specify an index predicate for the index target.
|
|
149
|
+
*
|
|
150
|
+
* See {@link WhereInterface.orWhereNotExists} for more info.
|
|
151
|
+
*/
|
|
152
|
+
orWhereNotExists(arg) {
|
|
153
|
+
return new OnConflictBuilder({
|
|
154
|
+
...this.#props,
|
|
155
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Adds the "do nothing" conflict action.
|
|
160
|
+
*
|
|
161
|
+
* ### Examples
|
|
162
|
+
*
|
|
163
|
+
* ```ts
|
|
164
|
+
* await db
|
|
165
|
+
* .insertInto('person')
|
|
166
|
+
* .values({ first_name, pic })
|
|
167
|
+
* .onConflict((oc) => oc
|
|
168
|
+
* .column('pic')
|
|
169
|
+
* .doNothing()
|
|
170
|
+
* )
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* The generated SQL (PostgreSQL):
|
|
174
|
+
*
|
|
175
|
+
* ```sql
|
|
176
|
+
* insert into "person" ("first_name", "pic")
|
|
177
|
+
* values ($1, $2)
|
|
178
|
+
* on conflict ("pic") do nothing
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
doNothing() {
|
|
182
|
+
return new OnConflictDoNothingBuilder({
|
|
183
|
+
...this.#props,
|
|
184
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
185
|
+
doNothing: true,
|
|
186
|
+
}),
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Adds the "do update set" conflict action.
|
|
191
|
+
*
|
|
192
|
+
* ### Examples
|
|
193
|
+
*
|
|
194
|
+
* ```ts
|
|
195
|
+
* await db
|
|
196
|
+
* .insertInto('person')
|
|
197
|
+
* .values({ first_name, pic })
|
|
198
|
+
* .onConflict((oc) => oc
|
|
199
|
+
* .column('pic')
|
|
200
|
+
* .doUpdateSet({ first_name })
|
|
201
|
+
* )
|
|
202
|
+
* ```
|
|
203
|
+
*
|
|
204
|
+
* The generated SQL (PostgreSQL):
|
|
205
|
+
*
|
|
206
|
+
* ```sql
|
|
207
|
+
* insert into "person" ("first_name", "pic")
|
|
208
|
+
* values ($1, $2)
|
|
209
|
+
* on conflict ("pic")
|
|
210
|
+
* do update set "first_name" = $3
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
doUpdateSet(updates) {
|
|
214
|
+
return new OnConflictUpdateBuilder({
|
|
215
|
+
...this.#props,
|
|
216
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWith(this.#props.onConflictNode, {
|
|
217
|
+
updates: (0, update_set_parser_js_1.parseUpdateObject)(this.#props.parseContext, updates),
|
|
218
|
+
}),
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
exports.OnConflictBuilder = OnConflictBuilder;
|
|
223
|
+
(0, prevent_await_js_1.preventAwait)(OnConflictBuilder, "don't await OnConflictBuilder instances.");
|
|
224
|
+
class OnConflictDoNothingBuilder {
|
|
225
|
+
#props;
|
|
226
|
+
constructor(props) {
|
|
227
|
+
this.#props = (0, object_utils_js_1.freeze)(props);
|
|
228
|
+
}
|
|
229
|
+
toOperationNode() {
|
|
230
|
+
return this.#props.onConflictNode;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
exports.OnConflictDoNothingBuilder = OnConflictDoNothingBuilder;
|
|
234
|
+
(0, prevent_await_js_1.preventAwait)(OnConflictDoNothingBuilder, "don't await OnConflictDoNothingBuilder instances.");
|
|
235
|
+
class OnConflictUpdateBuilder {
|
|
236
|
+
#props;
|
|
237
|
+
constructor(props) {
|
|
238
|
+
this.#props = (0, object_utils_js_1.freeze)(props);
|
|
239
|
+
}
|
|
240
|
+
where(...args) {
|
|
241
|
+
return new OnConflictUpdateBuilder({
|
|
242
|
+
...this.#props,
|
|
243
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseWhereFilter)(this.#props.parseContext, args)),
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Specify a where condition for the update operation.
|
|
248
|
+
*
|
|
249
|
+
* See {@link WhereInterface.whereRef} for more info.
|
|
250
|
+
*/
|
|
251
|
+
whereRef(lhs, op, rhs) {
|
|
252
|
+
return new OnConflictUpdateBuilder({
|
|
253
|
+
...this.#props,
|
|
254
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
orWhere(...args) {
|
|
258
|
+
return new OnConflictUpdateBuilder({
|
|
259
|
+
...this.#props,
|
|
260
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseWhereFilter)(this.#props.parseContext, args)),
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Specify a where condition for the update operation.
|
|
265
|
+
*
|
|
266
|
+
* See {@link WhereInterface.orWhereRef} for more info.
|
|
267
|
+
*/
|
|
268
|
+
orWhereRef(lhs, op, rhs) {
|
|
269
|
+
return new OnConflictUpdateBuilder({
|
|
270
|
+
...this.#props,
|
|
271
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseReferenceFilter)(this.#props.parseContext, lhs, op, rhs)),
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Specify a where condition for the update operation.
|
|
276
|
+
*
|
|
277
|
+
* See {@link WhereInterface.whereExists} for more info.
|
|
278
|
+
*/
|
|
279
|
+
whereExists(arg) {
|
|
280
|
+
return new OnConflictUpdateBuilder({
|
|
281
|
+
...this.#props,
|
|
282
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Specify a where condition for the update operation.
|
|
287
|
+
*
|
|
288
|
+
* See {@link WhereInterface.whereNotExists} for more info.
|
|
289
|
+
*/
|
|
290
|
+
whereNotExists(arg) {
|
|
291
|
+
return new OnConflictUpdateBuilder({
|
|
292
|
+
...this.#props,
|
|
293
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithUpdateWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Specify a where condition for the update operation.
|
|
298
|
+
*
|
|
299
|
+
* See {@link WhereInterface.orWhereExists} for more info.
|
|
300
|
+
*/
|
|
301
|
+
orWhereExists(arg) {
|
|
302
|
+
return new OnConflictUpdateBuilder({
|
|
303
|
+
...this.#props,
|
|
304
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseExistFilter)(this.#props.parseContext, arg)),
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Specify a where condition for the update operation.
|
|
309
|
+
*
|
|
310
|
+
* See {@link WhereInterface.orWhereNotExists} for more info.
|
|
311
|
+
*/
|
|
312
|
+
orWhereNotExists(arg) {
|
|
313
|
+
return new OnConflictUpdateBuilder({
|
|
314
|
+
...this.#props,
|
|
315
|
+
onConflictNode: on_conflict_node_js_1.OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, (0, filter_parser_js_1.parseNotExistFilter)(this.#props.parseContext, arg)),
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
toOperationNode() {
|
|
319
|
+
return this.#props.onConflictNode;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
exports.OnConflictUpdateBuilder = OnConflictUpdateBuilder;
|
|
323
|
+
(0, prevent_await_js_1.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;
|
|
@@ -327,9 +327,9 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
327
327
|
if (node.unsigned) {
|
|
328
328
|
this.append(' unsigned');
|
|
329
329
|
}
|
|
330
|
-
if (node.
|
|
330
|
+
if (node.generated) {
|
|
331
331
|
this.append(' ');
|
|
332
|
-
this.visitNode(node.
|
|
332
|
+
this.visitNode(node.generated);
|
|
333
333
|
}
|
|
334
334
|
if (node.defaultTo) {
|
|
335
335
|
this.append(' ');
|
|
@@ -454,16 +454,29 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
454
454
|
this.compileList(node.columns);
|
|
455
455
|
this.append(')');
|
|
456
456
|
}
|
|
457
|
-
if (node.constraint) {
|
|
457
|
+
else if (node.constraint) {
|
|
458
458
|
this.append(' on constraint ');
|
|
459
459
|
this.visitNode(node.constraint);
|
|
460
460
|
}
|
|
461
|
+
else if (node.indexExpression) {
|
|
462
|
+
this.append(' (');
|
|
463
|
+
this.visitNode(node.indexExpression);
|
|
464
|
+
this.append(')');
|
|
465
|
+
}
|
|
466
|
+
if (node.indexWhere) {
|
|
467
|
+
this.append(' ');
|
|
468
|
+
this.visitNode(node.indexWhere);
|
|
469
|
+
}
|
|
461
470
|
if (node.doNothing === true) {
|
|
462
471
|
this.append(' do nothing');
|
|
463
472
|
}
|
|
464
473
|
else if (node.updates) {
|
|
465
474
|
this.append(' do update set ');
|
|
466
475
|
this.compileList(node.updates);
|
|
476
|
+
if (node.updateWhere) {
|
|
477
|
+
this.append(' ');
|
|
478
|
+
this.visitNode(node.updateWhere);
|
|
479
|
+
}
|
|
467
480
|
}
|
|
468
481
|
}
|
|
469
482
|
visitOnDuplicateKey(node) {
|
|
@@ -725,10 +738,23 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
725
738
|
}
|
|
726
739
|
this.visitNode(node.name);
|
|
727
740
|
}
|
|
728
|
-
|
|
729
|
-
this.append('generated
|
|
730
|
-
|
|
731
|
-
|
|
741
|
+
visitGenerated(node) {
|
|
742
|
+
this.append('generated ');
|
|
743
|
+
if (node.always) {
|
|
744
|
+
this.append('always ');
|
|
745
|
+
}
|
|
746
|
+
if (node.byDefault) {
|
|
747
|
+
this.append('by default ');
|
|
748
|
+
}
|
|
749
|
+
this.append('as ');
|
|
750
|
+
if (node.identity) {
|
|
751
|
+
this.append('identity');
|
|
752
|
+
}
|
|
753
|
+
if (node.expression) {
|
|
754
|
+
this.append('(');
|
|
755
|
+
this.visitNode(node.expression);
|
|
756
|
+
this.append(')');
|
|
757
|
+
}
|
|
732
758
|
if (node.stored) {
|
|
733
759
|
this.append(' stored');
|
|
734
760
|
}
|
|
@@ -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
|
* })
|
|
@@ -46,7 +46,6 @@ class QueryCreator {
|
|
|
46
46
|
* const result = await db
|
|
47
47
|
* .insertInto('person')
|
|
48
48
|
* .values({
|
|
49
|
-
* id: db.generated,
|
|
50
49
|
* first_name: 'Jennifer',
|
|
51
50
|
* last_name: 'Aniston'
|
|
52
51
|
* })
|
|
@@ -61,7 +60,6 @@ class QueryCreator {
|
|
|
61
60
|
* const { id } = await db
|
|
62
61
|
* .insertInto('person')
|
|
63
62
|
* .values({
|
|
64
|
-
* id: db.generated,
|
|
65
63
|
* first_name: 'Jennifer',
|
|
66
64
|
* last_name: 'Aniston'
|
|
67
65
|
* })
|
|
@@ -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}
|