kysely 0.12.1 → 0.14.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 +34 -10
- 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-adapter.d.ts +2 -2
- package/dist/cjs/dialect/mysql/mysql-adapter.js +2 -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/postgres/postgres-adapter.d.ts +2 -2
- package/dist/cjs/dialect/postgres/postgres-adapter.js +2 -1
- 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/sqlite/sqlite-adapter.d.ts +2 -2
- 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/index.d.ts +5 -3
- package/dist/cjs/index.js +4 -2
- package/dist/cjs/kysely.d.ts +152 -1
- package/dist/cjs/kysely.js +37 -0
- package/dist/cjs/migration/migration.d.ts +154 -11
- package/dist/cjs/migration/migration.js +256 -135
- 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 +8 -7
- package/dist/cjs/operation-node/column-definition-node.js +0 -4
- package/dist/cjs/operation-node/common-table-expression-name-node.d.ts +15 -0
- package/dist/cjs/operation-node/common-table-expression-name-node.js +23 -0
- package/dist/cjs/operation-node/common-table-expression-node.d.ts +3 -3
- 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 +4 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +22 -6
- package/dist/cjs/operation-node/operation-node-visitor.d.ts +4 -2
- package/dist/cjs/operation-node/operation-node-visitor.js +2 -1
- package/dist/cjs/operation-node/operation-node.d.ts +1 -1
- package/dist/cjs/operation-node/with-node.d.ts +3 -1
- package/dist/cjs/operation-node/with-node.js +2 -1
- package/dist/cjs/parser/reference-parser.d.ts +2 -2
- package/dist/cjs/parser/select-parser.d.ts +2 -2
- package/dist/cjs/parser/with-parser.d.ts +32 -5
- package/dist/cjs/parser/with-parser.js +13 -2
- package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +2 -2
- package/dist/cjs/plugin/with-schema/with-schema-transformer.js +8 -0
- package/dist/cjs/query-builder/insert-query-builder.d.ts +76 -75
- package/dist/cjs/query-builder/insert-query-builder.js +150 -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-compiler/default-query-compiler.d.ts +4 -2
- package/dist/cjs/query-compiler/default-query-compiler.js +48 -8
- package/dist/cjs/query-creator.d.ts +27 -3
- package/dist/cjs/query-creator.js +33 -1
- package/dist/cjs/query-executor/default-query-executor.d.ts +19 -0
- package/dist/cjs/query-executor/noop-query-executor.d.ts +19 -0
- package/dist/cjs/raw-builder/raw-builder.js +1 -1
- package/dist/cjs/schema/alter-table-builder.d.ts +41 -9
- package/dist/cjs/schema/alter-table-builder.js +45 -9
- package/dist/cjs/schema/column-definition-builder.d.ts +40 -8
- package/dist/cjs/schema/column-definition-builder.js +21 -8
- 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/type-utils.d.ts +11 -7
- 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-adapter.d.ts +2 -2
- package/dist/esm/dialect/mysql/mysql-adapter.js +2 -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/postgres/postgres-adapter.d.ts +2 -2
- package/dist/esm/dialect/postgres/postgres-adapter.js +2 -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/sqlite/sqlite-adapter.d.ts +2 -2
- 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/index.d.ts +5 -3
- package/dist/esm/index.js +4 -2
- package/dist/esm/kysely.d.ts +152 -1
- package/dist/esm/kysely.js +37 -0
- package/dist/esm/migration/migration.d.ts +154 -11
- package/dist/esm/migration/migration.js +255 -134
- 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 +8 -7
- package/dist/esm/operation-node/column-definition-node.js +0 -4
- package/dist/esm/operation-node/common-table-expression-name-node.d.ts +15 -0
- package/dist/esm/operation-node/common-table-expression-name-node.js +20 -0
- package/dist/esm/operation-node/common-table-expression-node.d.ts +3 -3
- 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 +4 -2
- package/dist/esm/operation-node/operation-node-transformer.js +22 -6
- package/dist/esm/operation-node/operation-node-visitor.d.ts +4 -2
- package/dist/esm/operation-node/operation-node-visitor.js +2 -1
- package/dist/esm/operation-node/operation-node.d.ts +1 -1
- package/dist/esm/operation-node/with-node.d.ts +3 -1
- package/dist/esm/operation-node/with-node.js +2 -1
- package/dist/esm/parser/reference-parser.d.ts +2 -2
- package/dist/esm/parser/select-parser.d.ts +2 -2
- package/dist/esm/parser/with-parser.d.ts +32 -5
- package/dist/esm/parser/with-parser.js +13 -2
- package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +2 -2
- package/dist/esm/plugin/with-schema/with-schema-transformer.js +8 -0
- package/dist/esm/query-builder/insert-query-builder.d.ts +76 -75
- package/dist/esm/query-builder/insert-query-builder.js +150 -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-compiler/default-query-compiler.d.ts +4 -2
- package/dist/esm/query-compiler/default-query-compiler.js +48 -8
- package/dist/esm/query-creator.d.ts +27 -3
- package/dist/esm/query-creator.js +33 -1
- package/dist/esm/query-executor/default-query-executor.d.ts +19 -0
- package/dist/esm/query-executor/noop-query-executor.d.ts +19 -0
- package/dist/esm/raw-builder/raw-builder.js +1 -1
- package/dist/esm/schema/alter-table-builder.d.ts +41 -9
- package/dist/esm/schema/alter-table-builder.js +45 -9
- package/dist/esm/schema/column-definition-builder.d.ts +40 -8
- package/dist/esm/schema/column-definition-builder.js +21 -8
- 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/type-utils.d.ts +11 -7
- package/package.json +2 -2
- 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/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
|
@@ -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({ id: db.generated, 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({ id: db.generated, 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.");
|
|
@@ -64,10 +64,11 @@ 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';
|
|
71
|
+
import { CommonTableExpressionNameNode } from '../operation-node/common-table-expression-name-node.js';
|
|
71
72
|
export declare class DefaultQueryCompiler extends OperationNodeVisitor implements QueryCompiler {
|
|
72
73
|
#private;
|
|
73
74
|
protected get numParameters(): number;
|
|
@@ -129,6 +130,7 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
129
130
|
protected visitList(node: ListNode): void;
|
|
130
131
|
protected visitWith(node: WithNode): void;
|
|
131
132
|
protected visitCommonTableExpression(node: CommonTableExpressionNode): void;
|
|
133
|
+
protected visitCommonTableExpressionName(node: CommonTableExpressionNameNode): void;
|
|
132
134
|
protected visitAlterTable(node: AlterTableNode): void;
|
|
133
135
|
protected visitAddColumn(node: AddColumnNode): void;
|
|
134
136
|
protected visitRenameColumn(node: RenameColumnNode): void;
|
|
@@ -140,7 +142,7 @@ export declare class DefaultQueryCompiler extends OperationNodeVisitor implement
|
|
|
140
142
|
protected visitUnion(node: UnionNode): void;
|
|
141
143
|
protected visitCreateView(node: CreateViewNode): void;
|
|
142
144
|
protected visitDropView(node: DropViewNode): void;
|
|
143
|
-
protected
|
|
145
|
+
protected visitGenerated(node: GeneratedNode): void;
|
|
144
146
|
protected visitDefaultValue(node: DefaultValueNode): void;
|
|
145
147
|
protected append(str: string): void;
|
|
146
148
|
protected appendValue(parameter: unknown): void;
|
|
@@ -324,15 +324,18 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
324
324
|
this.visitNode(node.column);
|
|
325
325
|
this.append(' ');
|
|
326
326
|
this.visitNode(node.dataType);
|
|
327
|
-
if (node.
|
|
327
|
+
if (node.unsigned) {
|
|
328
|
+
this.append(' unsigned');
|
|
329
|
+
}
|
|
330
|
+
if (node.generated) {
|
|
328
331
|
this.append(' ');
|
|
329
|
-
this.visitNode(node.
|
|
332
|
+
this.visitNode(node.generated);
|
|
330
333
|
}
|
|
331
334
|
if (node.defaultTo) {
|
|
332
335
|
this.append(' ');
|
|
333
336
|
this.visitNode(node.defaultTo);
|
|
334
337
|
}
|
|
335
|
-
if (
|
|
338
|
+
if (node.notNull) {
|
|
336
339
|
this.append(' not null');
|
|
337
340
|
}
|
|
338
341
|
if (node.unique) {
|
|
@@ -451,16 +454,29 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
451
454
|
this.compileList(node.columns);
|
|
452
455
|
this.append(')');
|
|
453
456
|
}
|
|
454
|
-
if (node.constraint) {
|
|
457
|
+
else if (node.constraint) {
|
|
455
458
|
this.append(' on constraint ');
|
|
456
459
|
this.visitNode(node.constraint);
|
|
457
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
|
+
}
|
|
458
470
|
if (node.doNothing === true) {
|
|
459
471
|
this.append(' do nothing');
|
|
460
472
|
}
|
|
461
473
|
else if (node.updates) {
|
|
462
474
|
this.append(' do update set ');
|
|
463
475
|
this.compileList(node.updates);
|
|
476
|
+
if (node.updateWhere) {
|
|
477
|
+
this.append(' ');
|
|
478
|
+
this.visitNode(node.updateWhere);
|
|
479
|
+
}
|
|
464
480
|
}
|
|
465
481
|
}
|
|
466
482
|
visitOnDuplicateKey(node) {
|
|
@@ -573,6 +589,9 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
573
589
|
}
|
|
574
590
|
visitWith(node) {
|
|
575
591
|
this.append('with ');
|
|
592
|
+
if (node.recursive) {
|
|
593
|
+
this.append('recursive ');
|
|
594
|
+
}
|
|
576
595
|
this.compileList(node.expressions);
|
|
577
596
|
}
|
|
578
597
|
visitCommonTableExpression(node) {
|
|
@@ -580,6 +599,14 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
580
599
|
this.append(' as ');
|
|
581
600
|
this.visitNode(node.expression);
|
|
582
601
|
}
|
|
602
|
+
visitCommonTableExpressionName(node) {
|
|
603
|
+
this.visitNode(node.table);
|
|
604
|
+
if (node.columns) {
|
|
605
|
+
this.append('(');
|
|
606
|
+
this.compileList(node.columns);
|
|
607
|
+
this.append(')');
|
|
608
|
+
}
|
|
609
|
+
}
|
|
583
610
|
visitAlterTable(node) {
|
|
584
611
|
this.append('alter table ');
|
|
585
612
|
this.visitNode(node.table);
|
|
@@ -711,10 +738,23 @@ class DefaultQueryCompiler extends operation_node_visitor_js_1.OperationNodeVisi
|
|
|
711
738
|
}
|
|
712
739
|
this.visitNode(node.name);
|
|
713
740
|
}
|
|
714
|
-
|
|
715
|
-
this.append('generated
|
|
716
|
-
|
|
717
|
-
|
|
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
|
+
}
|
|
718
758
|
if (node.stored) {
|
|
719
759
|
this.append(' stored');
|
|
720
760
|
}
|
|
@@ -5,7 +5,7 @@ import { UpdateQueryBuilder } from './query-builder/update-query-builder.js';
|
|
|
5
5
|
import { TableExpression, TableExpressionDatabase, TableExpressionTables, TableReference } from './parser/table-parser.js';
|
|
6
6
|
import { QueryExecutor } from './query-executor/query-executor.js';
|
|
7
7
|
import { RawBuilder } from './raw-builder/raw-builder.js';
|
|
8
|
-
import { CommonTableExpression, QueryCreatorWithCommonTableExpression } from './parser/with-parser.js';
|
|
8
|
+
import { CommonTableExpression, QueryCreatorWithCommonTableExpression, RecursiveCommonTableExpression } from './parser/with-parser.js';
|
|
9
9
|
import { WithNode } from './operation-node/with-node.js';
|
|
10
10
|
import { ParseContext } from './parser/parse-context.js';
|
|
11
11
|
import { InsertResult } from './query-builder/insert-result.js';
|
|
@@ -206,7 +206,7 @@ export declare class QueryCreator<DB> {
|
|
|
206
206
|
*/
|
|
207
207
|
updateTable<TR extends TableReference<DB>>(table: TR): UpdateQueryBuilder<TableExpressionDatabase<DB, TR>, TableExpressionTables<DB, never, TR>, UpdateResult>;
|
|
208
208
|
/**
|
|
209
|
-
* Creates a `with` query (
|
|
209
|
+
* Creates a `with` query (Common Table Expression).
|
|
210
210
|
*
|
|
211
211
|
* ### Examples
|
|
212
212
|
*
|
|
@@ -227,8 +227,32 @@ export declare class QueryCreator<DB> {
|
|
|
227
227
|
* .selectAll()
|
|
228
228
|
* .execute()
|
|
229
229
|
* ```
|
|
230
|
+
*
|
|
231
|
+
* The CTE name can optionally specify column names in addition to
|
|
232
|
+
* a name. In that case Kysely requires the expression to retun
|
|
233
|
+
* rows with the same columns.
|
|
234
|
+
*
|
|
235
|
+
* ```ts
|
|
236
|
+
* await db
|
|
237
|
+
* .with('jennifers(id, age)', (db) => db
|
|
238
|
+
* .selectFrom('person')
|
|
239
|
+
* .where('first_name', '=', 'Jennifer')
|
|
240
|
+
* // This is ok since we return columns with the same
|
|
241
|
+
* // names as specified by `jennifers(id, age)`.
|
|
242
|
+
* .select(['id', 'age'])
|
|
243
|
+
* )
|
|
244
|
+
* .selectFrom('jennifers')
|
|
245
|
+
* .selectAll()
|
|
246
|
+
* .execute()
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
with<N extends string, E extends CommonTableExpression<DB, N>>(name: N, expression: E): QueryCreatorWithCommonTableExpression<DB, N, E>;
|
|
250
|
+
/**
|
|
251
|
+
* Creates a recursive `with` query (Common Table Expression).
|
|
252
|
+
*
|
|
253
|
+
* See the {@link with} method for examples and more documentation.
|
|
230
254
|
*/
|
|
231
|
-
|
|
255
|
+
withRecursive<N extends string, E extends RecursiveCommonTableExpression<DB, N>>(name: N, expression: E): QueryCreatorWithCommonTableExpression<DB, N, E>;
|
|
232
256
|
/**
|
|
233
257
|
* Sets the schema to be used for all table references that don't explicitly
|
|
234
258
|
* specify a schema.
|
|
@@ -136,7 +136,7 @@ class QueryCreator {
|
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
|
-
* Creates a `with` query (
|
|
139
|
+
* Creates a `with` query (Common Table Expression).
|
|
140
140
|
*
|
|
141
141
|
* ### Examples
|
|
142
142
|
*
|
|
@@ -157,6 +157,24 @@ class QueryCreator {
|
|
|
157
157
|
* .selectAll()
|
|
158
158
|
* .execute()
|
|
159
159
|
* ```
|
|
160
|
+
*
|
|
161
|
+
* The CTE name can optionally specify column names in addition to
|
|
162
|
+
* a name. In that case Kysely requires the expression to retun
|
|
163
|
+
* rows with the same columns.
|
|
164
|
+
*
|
|
165
|
+
* ```ts
|
|
166
|
+
* await db
|
|
167
|
+
* .with('jennifers(id, age)', (db) => db
|
|
168
|
+
* .selectFrom('person')
|
|
169
|
+
* .where('first_name', '=', 'Jennifer')
|
|
170
|
+
* // This is ok since we return columns with the same
|
|
171
|
+
* // names as specified by `jennifers(id, age)`.
|
|
172
|
+
* .select(['id', 'age'])
|
|
173
|
+
* )
|
|
174
|
+
* .selectFrom('jennifers')
|
|
175
|
+
* .selectAll()
|
|
176
|
+
* .execute()
|
|
177
|
+
* ```
|
|
160
178
|
*/
|
|
161
179
|
with(name, expression) {
|
|
162
180
|
const cte = (0, with_parser_js_1.parseCommonTableExpression)(this.#props.parseContext, name, expression);
|
|
@@ -167,6 +185,20 @@ class QueryCreator {
|
|
|
167
185
|
: with_node_js_1.WithNode.create(cte),
|
|
168
186
|
});
|
|
169
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Creates a recursive `with` query (Common Table Expression).
|
|
190
|
+
*
|
|
191
|
+
* See the {@link with} method for examples and more documentation.
|
|
192
|
+
*/
|
|
193
|
+
withRecursive(name, expression) {
|
|
194
|
+
const cte = (0, with_parser_js_1.parseCommonTableExpression)(this.#props.parseContext, name, expression);
|
|
195
|
+
return new QueryCreator({
|
|
196
|
+
...this.#props,
|
|
197
|
+
withNode: this.#props.withNode
|
|
198
|
+
? with_node_js_1.WithNode.cloneWithExpression(this.#props.withNode, cte)
|
|
199
|
+
: with_node_js_1.WithNode.create(cte, { recursive: true }),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
170
202
|
/**
|
|
171
203
|
* Sets the schema to be used for all table references that don't explicitly
|
|
172
204
|
* specify a schema.
|
|
@@ -7,10 +7,29 @@ import { QueryExecutor } from './query-executor.js';
|
|
|
7
7
|
export declare class DefaultQueryExecutor extends QueryExecutor {
|
|
8
8
|
#private;
|
|
9
9
|
constructor(compiler: QueryCompiler, connectionProvider: ConnectionProvider, plugins?: KyselyPlugin[]);
|
|
10
|
+
/**
|
|
11
|
+
* Compiles the transformed query into SQL. You usually want to pass
|
|
12
|
+
* the output of {@link transformQuery} into this method but you can
|
|
13
|
+
* compile any query using this method.
|
|
14
|
+
*/
|
|
10
15
|
compileQuery(node: RootOperationNode): CompiledQuery;
|
|
11
16
|
protected executeQueryImpl<R>(compiledQuery: CompiledQuery): Promise<QueryResult<R>>;
|
|
17
|
+
/**
|
|
18
|
+
* Returns a copy of this executor with a plugin added as the
|
|
19
|
+
* last plugin.
|
|
20
|
+
*/
|
|
12
21
|
withPlugin(plugin: KyselyPlugin): DefaultQueryExecutor;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a copy of this executor with a plugin added as the
|
|
24
|
+
* first plugin.
|
|
25
|
+
*/
|
|
13
26
|
withPluginAtFront(plugin: KyselyPlugin): DefaultQueryExecutor;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a copy of this executor with a new connection provider.
|
|
29
|
+
*/
|
|
14
30
|
withConnectionProvider(connectionProvider: ConnectionProvider): QueryExecutor;
|
|
31
|
+
/**
|
|
32
|
+
* Returns a copy of this executor without any plugins.
|
|
33
|
+
*/
|
|
15
34
|
withoutPlugins(): QueryExecutor;
|
|
16
35
|
}
|
|
@@ -8,10 +8,29 @@ import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
|
8
8
|
* other needed things to actually execute queries.
|
|
9
9
|
*/
|
|
10
10
|
export declare class NoopQueryExecutor extends QueryExecutor {
|
|
11
|
+
/**
|
|
12
|
+
* Compiles the transformed query into SQL. You usually want to pass
|
|
13
|
+
* the output of {@link transformQuery} into this method but you can
|
|
14
|
+
* compile any query using this method.
|
|
15
|
+
*/
|
|
11
16
|
compileQuery(): CompiledQuery;
|
|
12
17
|
protected executeQueryImpl<R>(): Promise<QueryResult<R>>;
|
|
18
|
+
/**
|
|
19
|
+
* Returns a copy of this executor with a new connection provider.
|
|
20
|
+
*/
|
|
13
21
|
withConnectionProvider(): QueryExecutor;
|
|
22
|
+
/**
|
|
23
|
+
* Returns a copy of this executor with a plugin added as the
|
|
24
|
+
* last plugin.
|
|
25
|
+
*/
|
|
14
26
|
withPlugin(plugin: KyselyPlugin): NoopQueryExecutor;
|
|
27
|
+
/**
|
|
28
|
+
* Returns a copy of this executor with a plugin added as the
|
|
29
|
+
* first plugin.
|
|
30
|
+
*/
|
|
15
31
|
withPluginAtFront(plugin: KyselyPlugin): NoopQueryExecutor;
|
|
32
|
+
/**
|
|
33
|
+
* Returns a copy of this executor without any plugins.
|
|
34
|
+
*/
|
|
16
35
|
withoutPlugins(): QueryExecutor;
|
|
17
36
|
}
|
|
@@ -50,7 +50,7 @@ class RawBuilder {
|
|
|
50
50
|
if (match.index > 0 && sql[match.index - 1] === '\\') {
|
|
51
51
|
continue;
|
|
52
52
|
}
|
|
53
|
-
sqlFragments.push(sql.slice(sqlIdx, match.index).
|
|
53
|
+
sqlFragments.push(sql.slice(sqlIdx, match.index).replace(/\\\?/g, '?'));
|
|
54
54
|
argNodes.push(parseRawArg(str, parameters[paramIdx]));
|
|
55
55
|
sqlIdx = match.index + str.length;
|
|
56
56
|
++paramIdx;
|