kysely 0.23.0 → 0.23.2
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 +5 -0
- package/dist/cjs/operation-node/on-conflict-node.d.ts +2 -0
- package/dist/cjs/operation-node/on-conflict-node.js +12 -0
- package/dist/cjs/operation-node/query-node.d.ts +1 -0
- package/dist/cjs/operation-node/query-node.js +6 -0
- package/dist/cjs/operation-node/select-query-node.d.ts +4 -0
- package/dist/cjs/operation-node/select-query-node.js +24 -0
- package/dist/cjs/query-builder/delete-query-builder.d.ts +63 -1
- package/dist/cjs/query-builder/delete-query-builder.js +51 -1
- package/dist/cjs/query-builder/insert-query-builder.d.ts +44 -1
- package/dist/cjs/query-builder/insert-query-builder.js +45 -1
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +38 -0
- package/dist/cjs/query-builder/on-conflict-builder.js +12 -0
- package/dist/cjs/query-builder/select-query-builder.d.ts +138 -1
- package/dist/cjs/query-builder/select-query-builder.js +146 -1
- package/dist/cjs/query-builder/update-query-builder.d.ts +65 -1
- package/dist/cjs/query-builder/update-query-builder.js +53 -1
- package/dist/cjs/query-builder/where-interface.d.ts +19 -0
- package/dist/cjs/schema/alter-table-add-foreign-key-constraint-builder.d.ts +23 -0
- package/dist/cjs/schema/alter-table-add-foreign-key-constraint-builder.js +38 -0
- package/dist/cjs/schema/alter-table-builder.d.ts +4 -36
- package/dist/cjs/schema/alter-table-builder.js +12 -104
- package/dist/cjs/schema/alter-table-drop-constraint-builder.d.ts +21 -0
- package/dist/cjs/schema/alter-table-drop-constraint-builder.js +54 -0
- package/dist/cjs/schema/alter-table-executor.d.ts +18 -0
- package/dist/cjs/schema/alter-table-executor.js +22 -0
- package/dist/cjs/schema/create-index-builder.d.ts +1 -1
- package/dist/cjs/schema/create-index-builder.js +7 -7
- package/dist/cjs/schema/create-schema-builder.d.ts +1 -1
- package/dist/cjs/schema/create-schema-builder.js +2 -2
- package/dist/cjs/schema/create-table-builder.d.ts +1 -1
- package/dist/cjs/schema/create-table-builder.js +11 -11
- package/dist/cjs/schema/create-type-builder.d.ts +1 -1
- package/dist/cjs/schema/create-type-builder.js +2 -2
- package/dist/cjs/schema/create-view-builder.d.ts +1 -1
- package/dist/cjs/schema/create-view-builder.js +7 -7
- package/dist/cjs/schema/drop-index-builder.d.ts +1 -1
- package/dist/cjs/schema/drop-index-builder.js +4 -4
- package/dist/cjs/schema/drop-schema-builder.d.ts +1 -1
- package/dist/cjs/schema/drop-schema-builder.js +3 -3
- package/dist/cjs/schema/drop-table-builder.d.ts +1 -1
- package/dist/cjs/schema/drop-table-builder.js +3 -3
- package/dist/cjs/schema/drop-type-builder.d.ts +1 -1
- package/dist/cjs/schema/drop-type-builder.js +2 -2
- package/dist/cjs/schema/drop-view-builder.d.ts +1 -1
- package/dist/cjs/schema/drop-view-builder.js +4 -4
- package/dist/cjs/schema/schema.js +10 -10
- package/dist/cjs/util/type-error.d.ts +3 -0
- package/dist/cjs/util/type-error.js +2 -0
- package/dist/esm/operation-node/on-conflict-node.d.ts +2 -0
- package/dist/esm/operation-node/on-conflict-node.js +12 -0
- package/dist/esm/operation-node/query-node.d.ts +1 -0
- package/dist/esm/operation-node/query-node.js +6 -0
- package/dist/esm/operation-node/select-query-node.d.ts +4 -0
- package/dist/esm/operation-node/select-query-node.js +24 -0
- package/dist/esm/query-builder/delete-query-builder.d.ts +63 -1
- package/dist/esm/query-builder/delete-query-builder.js +51 -1
- package/dist/esm/query-builder/insert-query-builder.d.ts +44 -1
- package/dist/esm/query-builder/insert-query-builder.js +45 -1
- package/dist/esm/query-builder/on-conflict-builder.d.ts +38 -0
- package/dist/esm/query-builder/on-conflict-builder.js +12 -0
- package/dist/esm/query-builder/select-query-builder.d.ts +138 -1
- package/dist/esm/query-builder/select-query-builder.js +146 -1
- package/dist/esm/query-builder/update-query-builder.d.ts +65 -1
- package/dist/esm/query-builder/update-query-builder.js +53 -1
- package/dist/esm/query-builder/where-interface.d.ts +19 -0
- package/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.d.ts +23 -0
- package/dist/esm/schema/alter-table-add-foreign-key-constraint-builder.js +35 -0
- package/dist/esm/schema/alter-table-builder.d.ts +4 -36
- package/dist/esm/schema/alter-table-builder.js +5 -94
- package/dist/esm/schema/alter-table-drop-constraint-builder.d.ts +21 -0
- package/dist/esm/schema/alter-table-drop-constraint-builder.js +51 -0
- package/dist/esm/schema/alter-table-executor.d.ts +18 -0
- package/dist/esm/schema/alter-table-executor.js +19 -0
- package/dist/esm/schema/create-index-builder.d.ts +1 -1
- package/dist/esm/schema/create-index-builder.js +7 -7
- package/dist/esm/schema/create-schema-builder.d.ts +1 -1
- package/dist/esm/schema/create-schema-builder.js +2 -2
- package/dist/esm/schema/create-table-builder.d.ts +1 -1
- package/dist/esm/schema/create-table-builder.js +11 -11
- package/dist/esm/schema/create-type-builder.d.ts +1 -1
- package/dist/esm/schema/create-type-builder.js +2 -2
- package/dist/esm/schema/create-view-builder.d.ts +1 -1
- package/dist/esm/schema/create-view-builder.js +7 -7
- package/dist/esm/schema/drop-index-builder.d.ts +1 -1
- package/dist/esm/schema/drop-index-builder.js +4 -4
- package/dist/esm/schema/drop-schema-builder.d.ts +1 -1
- package/dist/esm/schema/drop-schema-builder.js +3 -3
- package/dist/esm/schema/drop-table-builder.d.ts +1 -1
- package/dist/esm/schema/drop-table-builder.js +3 -3
- package/dist/esm/schema/drop-type-builder.d.ts +1 -1
- package/dist/esm/schema/drop-type-builder.js +2 -2
- package/dist/esm/schema/drop-view-builder.d.ts +1 -1
- package/dist/esm/schema/drop-view-builder.js +4 -4
- package/dist/esm/schema/schema.js +10 -10
- package/dist/esm/util/type-error.d.ts +3 -0
- package/dist/esm/util/type-error.js +2 -0
- package/package.json +2 -2
|
@@ -90,7 +90,7 @@ class SchemaModule {
|
|
|
90
90
|
return new create_table_builder_js_1.CreateTableBuilder({
|
|
91
91
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
92
92
|
executor: this.#executor,
|
|
93
|
-
|
|
93
|
+
node: create_table_node_js_1.CreateTableNode.create((0, table_parser_js_1.parseTable)(table)),
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
@@ -108,7 +108,7 @@ class SchemaModule {
|
|
|
108
108
|
return new drop_table_builder_js_1.DropTableBuilder({
|
|
109
109
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
110
110
|
executor: this.#executor,
|
|
111
|
-
|
|
111
|
+
node: drop_table_node_js_1.DropTableNode.create((0, table_parser_js_1.parseTable)(table)),
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
@@ -128,7 +128,7 @@ class SchemaModule {
|
|
|
128
128
|
return new create_index_builder_js_1.CreateIndexBuilder({
|
|
129
129
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
130
130
|
executor: this.#executor,
|
|
131
|
-
|
|
131
|
+
node: create_index_node_js_1.CreateIndexNode.create(indexName),
|
|
132
132
|
});
|
|
133
133
|
}
|
|
134
134
|
/**
|
|
@@ -146,7 +146,7 @@ class SchemaModule {
|
|
|
146
146
|
return new drop_index_builder_js_1.DropIndexBuilder({
|
|
147
147
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
148
148
|
executor: this.#executor,
|
|
149
|
-
|
|
149
|
+
node: drop_index_node_js_1.DropIndexNode.create(indexName),
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
152
|
/**
|
|
@@ -164,7 +164,7 @@ class SchemaModule {
|
|
|
164
164
|
return new create_schema_builder_js_1.CreateSchemaBuilder({
|
|
165
165
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
166
166
|
executor: this.#executor,
|
|
167
|
-
|
|
167
|
+
node: create_schema_node_js_1.CreateSchemaNode.create(schema),
|
|
168
168
|
});
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
@@ -182,7 +182,7 @@ class SchemaModule {
|
|
|
182
182
|
return new drop_schema_builder_js_1.DropSchemaBuilder({
|
|
183
183
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
184
184
|
executor: this.#executor,
|
|
185
|
-
|
|
185
|
+
node: drop_schema_node_js_1.DropSchemaNode.create(schema),
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
/**
|
|
@@ -222,7 +222,7 @@ class SchemaModule {
|
|
|
222
222
|
return new create_view_builder_js_1.CreateViewBuilder({
|
|
223
223
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
224
224
|
executor: this.#executor,
|
|
225
|
-
|
|
225
|
+
node: create_view_node_js_1.CreateViewNode.create(viewName),
|
|
226
226
|
});
|
|
227
227
|
}
|
|
228
228
|
/**
|
|
@@ -241,7 +241,7 @@ class SchemaModule {
|
|
|
241
241
|
return new drop_view_builder_js_1.DropViewBuilder({
|
|
242
242
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
243
243
|
executor: this.#executor,
|
|
244
|
-
|
|
244
|
+
node: drop_view_node_js_1.DropViewNode.create(viewName),
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
247
|
/**
|
|
@@ -262,7 +262,7 @@ class SchemaModule {
|
|
|
262
262
|
return new create_type_builder_js_1.CreateTypeBuilder({
|
|
263
263
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
264
264
|
executor: this.#executor,
|
|
265
|
-
|
|
265
|
+
node: create_type_node_js_1.CreateTypeNode.create((0, identifier_parser_js_1.parseSchemableIdentifier)(typeName)),
|
|
266
266
|
});
|
|
267
267
|
}
|
|
268
268
|
/**
|
|
@@ -283,7 +283,7 @@ class SchemaModule {
|
|
|
283
283
|
return new drop_type_builder_js_1.DropTypeBuilder({
|
|
284
284
|
queryId: (0, query_id_js_1.createQueryId)(),
|
|
285
285
|
executor: this.#executor,
|
|
286
|
-
|
|
286
|
+
node: drop_type_node_js_1.DropTypeNode.create((0, identifier_parser_js_1.parseSchemableIdentifier)(typeName)),
|
|
287
287
|
});
|
|
288
288
|
}
|
|
289
289
|
/**
|
|
@@ -25,4 +25,6 @@ export declare const OnConflictNode: Readonly<{
|
|
|
25
25
|
cloneWithIndexOrWhere(node: OnConflictNode, operation: OperationNode): OnConflictNode;
|
|
26
26
|
cloneWithUpdateWhere(node: OnConflictNode, operation: OperationNode): OnConflictNode;
|
|
27
27
|
cloneWithUpdateOrWhere(node: OnConflictNode, operation: OperationNode): OnConflictNode;
|
|
28
|
+
cloneWithoutIndexWhere(node: OnConflictNode): OnConflictNode;
|
|
29
|
+
cloneWithoutUpdateWhere(node: OnConflictNode): OnConflictNode;
|
|
28
30
|
}>;
|
|
@@ -51,4 +51,16 @@ export const OnConflictNode = freeze({
|
|
|
51
51
|
: WhereNode.create(operation),
|
|
52
52
|
});
|
|
53
53
|
},
|
|
54
|
+
cloneWithoutIndexWhere(node) {
|
|
55
|
+
return freeze({
|
|
56
|
+
...node,
|
|
57
|
+
indexWhere: undefined,
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
cloneWithoutUpdateWhere(node) {
|
|
61
|
+
return freeze({
|
|
62
|
+
...node,
|
|
63
|
+
updateWhere: undefined,
|
|
64
|
+
});
|
|
65
|
+
},
|
|
54
66
|
});
|
|
@@ -17,4 +17,5 @@ export declare const QueryNode: Readonly<{
|
|
|
17
17
|
cloneWithOrWhere<T_1 extends FilterableQueryNode>(node: T_1, operation: OperationNode): T_1;
|
|
18
18
|
cloneWithJoin<T_2 extends FilterableQueryNode>(node: T_2, join: JoinNode): T_2;
|
|
19
19
|
cloneWithReturning<T_3 extends MutatingQueryNode>(node: T_3, selections: ReadonlyArray<SelectionNode>): T_3;
|
|
20
|
+
cloneWithoutWhere<T_4 extends FilterableQueryNode>(node: T_4): T_4;
|
|
20
21
|
}>;
|
|
@@ -50,4 +50,8 @@ export declare const SelectQueryNode: Readonly<{
|
|
|
50
50
|
cloneWithOrHaving(selectNode: SelectQueryNode, operation: OperationNode): SelectQueryNode;
|
|
51
51
|
cloneWithSetOperation(selectNode: SelectQueryNode, setOperation: SetOperationNode): SelectQueryNode;
|
|
52
52
|
cloneWithExplain(selectNode: SelectQueryNode, explain: ExplainNode): SelectQueryNode;
|
|
53
|
+
cloneWithoutSelections(select: SelectQueryNode): SelectQueryNode;
|
|
54
|
+
cloneWithoutLimit(select: SelectQueryNode): SelectQueryNode;
|
|
55
|
+
cloneWithoutOffset(select: SelectQueryNode): SelectQueryNode;
|
|
56
|
+
cloneWithoutOrderBy(select: SelectQueryNode): SelectQueryNode;
|
|
53
57
|
}>;
|
|
@@ -108,4 +108,28 @@ export const SelectQueryNode = freeze({
|
|
|
108
108
|
explain,
|
|
109
109
|
});
|
|
110
110
|
},
|
|
111
|
+
cloneWithoutSelections(select) {
|
|
112
|
+
return freeze({
|
|
113
|
+
...select,
|
|
114
|
+
selections: [],
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
cloneWithoutLimit(select) {
|
|
118
|
+
return freeze({
|
|
119
|
+
...select,
|
|
120
|
+
limit: undefined,
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
cloneWithoutOffset(select) {
|
|
124
|
+
return freeze({
|
|
125
|
+
...select,
|
|
126
|
+
offset: undefined,
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
cloneWithoutOrderBy(select) {
|
|
130
|
+
return freeze({
|
|
131
|
+
...select,
|
|
132
|
+
orderBy: undefined,
|
|
133
|
+
});
|
|
134
|
+
},
|
|
111
135
|
});
|
|
@@ -21,6 +21,7 @@ import { Explainable, ExplainFormat } from '../util/explainable.js';
|
|
|
21
21
|
import { AliasedExpression, Expression } from '../expression/expression.js';
|
|
22
22
|
import { ComparisonOperatorExpression, OperandValueExpressionOrList, WhereGrouper } from '../parser/binary-operation-parser.js';
|
|
23
23
|
import { ExistsExpression } from '../parser/unary-operation-parser.js';
|
|
24
|
+
import { KyselyTypeError } from '../util/type-error.js';
|
|
24
25
|
export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable<O>, Explainable {
|
|
25
26
|
#private;
|
|
26
27
|
constructor(props: DeleteQueryBuilderProps);
|
|
@@ -408,6 +409,25 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
408
409
|
* Just like {@link whereExists} but creates an `or not exists` clause.
|
|
409
410
|
*/
|
|
410
411
|
orWhereNotExists(arg: ExistsExpression<DB, TB>): DeleteQueryBuilder<DB, TB, O>;
|
|
412
|
+
/**
|
|
413
|
+
* Clears all where clauses from the query.
|
|
414
|
+
*
|
|
415
|
+
* ### Examples
|
|
416
|
+
*
|
|
417
|
+
* ```ts
|
|
418
|
+
* db.selectFrom('person')
|
|
419
|
+
* .selectAll()
|
|
420
|
+
* .where('id','=',42)
|
|
421
|
+
* .clearWhere()
|
|
422
|
+
* ```
|
|
423
|
+
*
|
|
424
|
+
* The generated SQL(PostgreSQL):
|
|
425
|
+
*
|
|
426
|
+
* ```sql
|
|
427
|
+
* select * from "person"
|
|
428
|
+
* ```
|
|
429
|
+
*/
|
|
430
|
+
clearWhere(): DeleteQueryBuilder<DB, TB, O>;
|
|
411
431
|
/**
|
|
412
432
|
* Joins another table to the query using an inner join.
|
|
413
433
|
*
|
|
@@ -662,7 +682,7 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
662
682
|
*
|
|
663
683
|
* ### Examples
|
|
664
684
|
*
|
|
665
|
-
* The next example uses a helper
|
|
685
|
+
* The next example uses a helper function `log` to log a query:
|
|
666
686
|
*
|
|
667
687
|
* ```ts
|
|
668
688
|
* function log<T extends Compilable>(qb: T): T {
|
|
@@ -719,6 +739,48 @@ export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
719
739
|
* don't support your use case.
|
|
720
740
|
*/
|
|
721
741
|
castTo<T>(): DeleteQueryBuilder<DB, TB, T>;
|
|
742
|
+
/**
|
|
743
|
+
* Asserts that query's output row type equals the given type `T`.
|
|
744
|
+
*
|
|
745
|
+
* This method can be used to simplify excessively complex types to make typescript happy
|
|
746
|
+
* and much faster.
|
|
747
|
+
*
|
|
748
|
+
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
|
|
749
|
+
* for typescript and you get errors like this:
|
|
750
|
+
*
|
|
751
|
+
* ```
|
|
752
|
+
* error TS2589: Type instantiation is excessively deep and possibly infinite.
|
|
753
|
+
* ```
|
|
754
|
+
*
|
|
755
|
+
* In these case you can often use this method to help typescript a little bit. When you use this
|
|
756
|
+
* method to assert the output type of a query, Kysely can drop the complex output type that
|
|
757
|
+
* consists of multiple nested helper types and replace it with the simple asserted type.
|
|
758
|
+
*
|
|
759
|
+
* Using this method doesn't reduce type safety at all. You have to pass in a type that is
|
|
760
|
+
* structurally equal to the current type.
|
|
761
|
+
*
|
|
762
|
+
* ### Examples
|
|
763
|
+
*
|
|
764
|
+
* ```ts
|
|
765
|
+
* const result = await db
|
|
766
|
+
* .with('deleted_person', (qb) => qb
|
|
767
|
+
* .deleteFrom('person')
|
|
768
|
+
* .where('id', '=', person.id)
|
|
769
|
+
* .returning('first_name')
|
|
770
|
+
* .assertType<{ first_name: string }>()
|
|
771
|
+
* )
|
|
772
|
+
* .with('deleted_pet', (qb) => qb
|
|
773
|
+
* .deleteFrom('pet')
|
|
774
|
+
* .where('owner_id', '=', person.id)
|
|
775
|
+
* .returning(['name as pet_name', 'species'])
|
|
776
|
+
* .assertType<{ pet_name: string, species: Species }>()
|
|
777
|
+
* )
|
|
778
|
+
* .selectFrom(['deleted_person', 'deleted_pet'])
|
|
779
|
+
* .selectAll()
|
|
780
|
+
* .executeTakeFirstOrThrow()
|
|
781
|
+
* ```
|
|
782
|
+
*/
|
|
783
|
+
assertType<T extends O>(): O extends T ? DeleteQueryBuilder<DB, TB, T> : KyselyTypeError<`assertType() call failed: The type passed in is not equal to the output type of the query.`>;
|
|
722
784
|
/**
|
|
723
785
|
* Returns a copy of this DeleteQueryBuilder instance with the given plugin installed.
|
|
724
786
|
*/
|
|
@@ -65,6 +65,12 @@ export class DeleteQueryBuilder {
|
|
|
65
65
|
queryNode: QueryNode.cloneWithOrWhere(this.#props.queryNode, parseNotExists(arg)),
|
|
66
66
|
});
|
|
67
67
|
}
|
|
68
|
+
clearWhere() {
|
|
69
|
+
return new DeleteQueryBuilder({
|
|
70
|
+
...this.#props,
|
|
71
|
+
queryNode: QueryNode.cloneWithoutWhere(this.#props.queryNode),
|
|
72
|
+
});
|
|
73
|
+
}
|
|
68
74
|
innerJoin(...args) {
|
|
69
75
|
return new DeleteQueryBuilder({
|
|
70
76
|
...this.#props,
|
|
@@ -173,7 +179,7 @@ export class DeleteQueryBuilder {
|
|
|
173
179
|
*
|
|
174
180
|
* ### Examples
|
|
175
181
|
*
|
|
176
|
-
* The next example uses a helper
|
|
182
|
+
* The next example uses a helper function `log` to log a query:
|
|
177
183
|
*
|
|
178
184
|
* ```ts
|
|
179
185
|
* function log<T extends Compilable>(qb: T): T {
|
|
@@ -241,6 +247,50 @@ export class DeleteQueryBuilder {
|
|
|
241
247
|
castTo() {
|
|
242
248
|
return new DeleteQueryBuilder(this.#props);
|
|
243
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Asserts that query's output row type equals the given type `T`.
|
|
252
|
+
*
|
|
253
|
+
* This method can be used to simplify excessively complex types to make typescript happy
|
|
254
|
+
* and much faster.
|
|
255
|
+
*
|
|
256
|
+
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
|
|
257
|
+
* for typescript and you get errors like this:
|
|
258
|
+
*
|
|
259
|
+
* ```
|
|
260
|
+
* error TS2589: Type instantiation is excessively deep and possibly infinite.
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* In these case you can often use this method to help typescript a little bit. When you use this
|
|
264
|
+
* method to assert the output type of a query, Kysely can drop the complex output type that
|
|
265
|
+
* consists of multiple nested helper types and replace it with the simple asserted type.
|
|
266
|
+
*
|
|
267
|
+
* Using this method doesn't reduce type safety at all. You have to pass in a type that is
|
|
268
|
+
* structurally equal to the current type.
|
|
269
|
+
*
|
|
270
|
+
* ### Examples
|
|
271
|
+
*
|
|
272
|
+
* ```ts
|
|
273
|
+
* const result = await db
|
|
274
|
+
* .with('deleted_person', (qb) => qb
|
|
275
|
+
* .deleteFrom('person')
|
|
276
|
+
* .where('id', '=', person.id)
|
|
277
|
+
* .returning('first_name')
|
|
278
|
+
* .assertType<{ first_name: string }>()
|
|
279
|
+
* )
|
|
280
|
+
* .with('deleted_pet', (qb) => qb
|
|
281
|
+
* .deleteFrom('pet')
|
|
282
|
+
* .where('owner_id', '=', person.id)
|
|
283
|
+
* .returning(['name as pet_name', 'species'])
|
|
284
|
+
* .assertType<{ pet_name: string, species: Species }>()
|
|
285
|
+
* )
|
|
286
|
+
* .selectFrom(['deleted_person', 'deleted_pet'])
|
|
287
|
+
* .selectAll()
|
|
288
|
+
* .executeTakeFirstOrThrow()
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
assertType() {
|
|
292
|
+
return new DeleteQueryBuilder(this.#props);
|
|
293
|
+
}
|
|
244
294
|
/**
|
|
245
295
|
* Returns a copy of this DeleteQueryBuilder instance with the given plugin installed.
|
|
246
296
|
*/
|
|
@@ -18,6 +18,7 @@ import { OnConflictBuilder, OnConflictDoNothingBuilder, OnConflictUpdateBuilder
|
|
|
18
18
|
import { Selectable } from '../util/column-type.js';
|
|
19
19
|
import { Explainable, ExplainFormat } from '../util/explainable.js';
|
|
20
20
|
import { Expression } from '../expression/expression.js';
|
|
21
|
+
import { KyselyTypeError } from '../util/type-error.js';
|
|
21
22
|
export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable<O>, Explainable {
|
|
22
23
|
#private;
|
|
23
24
|
constructor(props: InsertQueryBuilderProps);
|
|
@@ -459,7 +460,7 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
459
460
|
*
|
|
460
461
|
* ### Examples
|
|
461
462
|
*
|
|
462
|
-
* The next example uses a helper
|
|
463
|
+
* The next example uses a helper function `log` to log a query:
|
|
463
464
|
*
|
|
464
465
|
* ```ts
|
|
465
466
|
* function log<T extends Compilable>(qb: T): T {
|
|
@@ -517,6 +518,48 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
517
518
|
* don't support your use case.
|
|
518
519
|
*/
|
|
519
520
|
castTo<T>(): InsertQueryBuilder<DB, TB, T>;
|
|
521
|
+
/**
|
|
522
|
+
* Asserts that query's output row type equals the given type `T`.
|
|
523
|
+
*
|
|
524
|
+
* This method can be used to simplify excessively complex types to make typescript happy
|
|
525
|
+
* and much faster.
|
|
526
|
+
*
|
|
527
|
+
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
|
|
528
|
+
* for typescript and you get errors like this:
|
|
529
|
+
*
|
|
530
|
+
* ```
|
|
531
|
+
* error TS2589: Type instantiation is excessively deep and possibly infinite.
|
|
532
|
+
* ```
|
|
533
|
+
*
|
|
534
|
+
* In these case you can often use this method to help typescript a little bit. When you use this
|
|
535
|
+
* method to assert the output type of a query, Kysely can drop the complex output type that
|
|
536
|
+
* consists of multiple nested helper types and replace it with the simple asserted type.
|
|
537
|
+
*
|
|
538
|
+
* Using this method doesn't reduce type safety at all. You have to pass in a type that is
|
|
539
|
+
* structurally equal to the current type.
|
|
540
|
+
*
|
|
541
|
+
* ### Examples
|
|
542
|
+
*
|
|
543
|
+
* ```ts
|
|
544
|
+
* const result = await db
|
|
545
|
+
* .with('new_person', (qb) => qb
|
|
546
|
+
* .insertInto('person')
|
|
547
|
+
* .values(person)
|
|
548
|
+
* .returning('id')
|
|
549
|
+
* .assertType<{ id: string }>()
|
|
550
|
+
* )
|
|
551
|
+
* .with('new_pet', (qb) => qb
|
|
552
|
+
* .insertInto('pet')
|
|
553
|
+
* .values({ owner_id: (eb) => eb.selectFrom('new_person').select('id'), ...pet })
|
|
554
|
+
* .returning(['name as pet_name', 'species'])
|
|
555
|
+
* .assertType<{ pet_name: string, species: Species }>()
|
|
556
|
+
* )
|
|
557
|
+
* .selectFrom(['new_person', 'new_pet'])
|
|
558
|
+
* .selectAll()
|
|
559
|
+
* .executeTakeFirstOrThrow()
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
assertType<T extends O>(): O extends T ? InsertQueryBuilder<DB, TB, T> : KyselyTypeError<`assertType() call failed: The type passed in is not equal to the output type of the query.`>;
|
|
520
563
|
/**
|
|
521
564
|
* Returns a copy of this InsertQueryBuilder instance with the given plugin installed.
|
|
522
565
|
*/
|
|
@@ -322,7 +322,7 @@ export class InsertQueryBuilder {
|
|
|
322
322
|
*
|
|
323
323
|
* ### Examples
|
|
324
324
|
*
|
|
325
|
-
* The next example uses a helper
|
|
325
|
+
* The next example uses a helper function `log` to log a query:
|
|
326
326
|
*
|
|
327
327
|
* ```ts
|
|
328
328
|
* function log<T extends Compilable>(qb: T): T {
|
|
@@ -391,6 +391,50 @@ export class InsertQueryBuilder {
|
|
|
391
391
|
castTo() {
|
|
392
392
|
return new InsertQueryBuilder(this.#props);
|
|
393
393
|
}
|
|
394
|
+
/**
|
|
395
|
+
* Asserts that query's output row type equals the given type `T`.
|
|
396
|
+
*
|
|
397
|
+
* This method can be used to simplify excessively complex types to make typescript happy
|
|
398
|
+
* and much faster.
|
|
399
|
+
*
|
|
400
|
+
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
|
|
401
|
+
* for typescript and you get errors like this:
|
|
402
|
+
*
|
|
403
|
+
* ```
|
|
404
|
+
* error TS2589: Type instantiation is excessively deep and possibly infinite.
|
|
405
|
+
* ```
|
|
406
|
+
*
|
|
407
|
+
* In these case you can often use this method to help typescript a little bit. When you use this
|
|
408
|
+
* method to assert the output type of a query, Kysely can drop the complex output type that
|
|
409
|
+
* consists of multiple nested helper types and replace it with the simple asserted type.
|
|
410
|
+
*
|
|
411
|
+
* Using this method doesn't reduce type safety at all. You have to pass in a type that is
|
|
412
|
+
* structurally equal to the current type.
|
|
413
|
+
*
|
|
414
|
+
* ### Examples
|
|
415
|
+
*
|
|
416
|
+
* ```ts
|
|
417
|
+
* const result = await db
|
|
418
|
+
* .with('new_person', (qb) => qb
|
|
419
|
+
* .insertInto('person')
|
|
420
|
+
* .values(person)
|
|
421
|
+
* .returning('id')
|
|
422
|
+
* .assertType<{ id: string }>()
|
|
423
|
+
* )
|
|
424
|
+
* .with('new_pet', (qb) => qb
|
|
425
|
+
* .insertInto('pet')
|
|
426
|
+
* .values({ owner_id: (eb) => eb.selectFrom('new_person').select('id'), ...pet })
|
|
427
|
+
* .returning(['name as pet_name', 'species'])
|
|
428
|
+
* .assertType<{ pet_name: string, species: Species }>()
|
|
429
|
+
* )
|
|
430
|
+
* .selectFrom(['new_person', 'new_pet'])
|
|
431
|
+
* .selectAll()
|
|
432
|
+
* .executeTakeFirstOrThrow()
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
assertType() {
|
|
436
|
+
return new InsertQueryBuilder(this.#props);
|
|
437
|
+
}
|
|
394
438
|
/**
|
|
395
439
|
* Returns a copy of this InsertQueryBuilder instance with the given plugin installed.
|
|
396
440
|
*/
|
|
@@ -339,6 +339,25 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
|
|
|
339
339
|
* See {@link WhereInterface.orWhereNotExists} for more info.
|
|
340
340
|
*/
|
|
341
341
|
orWhereNotExists(arg: ExpressionOrFactory<DB, TB, any>): OnConflictBuilder<DB, TB>;
|
|
342
|
+
/**
|
|
343
|
+
* Clears all where clauses from the query.
|
|
344
|
+
*
|
|
345
|
+
* ### Examples
|
|
346
|
+
*
|
|
347
|
+
* ```ts
|
|
348
|
+
* db.selectFrom('person')
|
|
349
|
+
* .selectAll()
|
|
350
|
+
* .where('id','=',42)
|
|
351
|
+
* .clearWhere()
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* The generated SQL(PostgreSQL):
|
|
355
|
+
*
|
|
356
|
+
* ```sql
|
|
357
|
+
* select * from "person"
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
clearWhere(): OnConflictBuilder<DB, TB>;
|
|
342
361
|
/**
|
|
343
362
|
* Adds the "do nothing" conflict action.
|
|
344
363
|
*
|
|
@@ -703,5 +722,24 @@ export declare class OnConflictUpdateBuilder<DB, TB extends keyof DB> implements
|
|
|
703
722
|
* See {@link WhereInterface.orWhereNotExists} for more info.
|
|
704
723
|
*/
|
|
705
724
|
orWhereNotExists(arg: ExpressionOrFactory<DB, TB, any>): OnConflictUpdateBuilder<DB, TB>;
|
|
725
|
+
/**
|
|
726
|
+
* Clears all where clauses from the query.
|
|
727
|
+
*
|
|
728
|
+
* ### Examples
|
|
729
|
+
*
|
|
730
|
+
* ```ts
|
|
731
|
+
* db.selectFrom('person')
|
|
732
|
+
* .selectAll()
|
|
733
|
+
* .where('id','=',42)
|
|
734
|
+
* .clearWhere()
|
|
735
|
+
* ```
|
|
736
|
+
*
|
|
737
|
+
* The generated SQL(PostgreSQL):
|
|
738
|
+
*
|
|
739
|
+
* ```sql
|
|
740
|
+
* select * from "person"
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
clearWhere(): OnConflictUpdateBuilder<DB, TB>;
|
|
706
744
|
toOperationNode(): OnConflictNode;
|
|
707
745
|
}
|
|
@@ -154,6 +154,12 @@ export class OnConflictBuilder {
|
|
|
154
154
|
onConflictNode: OnConflictNode.cloneWithIndexOrWhere(this.#props.onConflictNode, parseNotExists(arg)),
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
|
+
clearWhere() {
|
|
158
|
+
return new OnConflictBuilder({
|
|
159
|
+
...this.#props,
|
|
160
|
+
onConflictNode: OnConflictNode.cloneWithoutIndexWhere(this.#props.onConflictNode),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
157
163
|
/**
|
|
158
164
|
* Adds the "do nothing" conflict action.
|
|
159
165
|
*
|
|
@@ -312,6 +318,12 @@ export class OnConflictUpdateBuilder {
|
|
|
312
318
|
onConflictNode: OnConflictNode.cloneWithUpdateOrWhere(this.#props.onConflictNode, parseNotExists(arg)),
|
|
313
319
|
});
|
|
314
320
|
}
|
|
321
|
+
clearWhere() {
|
|
322
|
+
return new OnConflictUpdateBuilder({
|
|
323
|
+
...this.#props,
|
|
324
|
+
onConflictNode: OnConflictNode.cloneWithoutUpdateWhere(this.#props.onConflictNode),
|
|
325
|
+
});
|
|
326
|
+
}
|
|
315
327
|
toOperationNode() {
|
|
316
328
|
return this.#props.onConflictNode;
|
|
317
329
|
}
|