kysely 0.23.1 → 0.23.3
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/dialect/mysql/mysql-introspector.js +1 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +1 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +1 -1
- package/dist/cjs/index.d.ts +1 -1
- 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/parser/binary-operation-parser.d.ts +1 -1
- package/dist/cjs/parser/update-set-parser.d.ts +3 -3
- package/dist/cjs/parser/update-set-parser.js +2 -2
- 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 +46 -3
- package/dist/cjs/query-builder/insert-query-builder.js +45 -1
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +40 -2
- 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 +67 -3
- 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 +3 -35
- package/dist/cjs/schema/alter-table-builder.js +10 -102
- 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/util/type-error.d.ts +3 -0
- package/dist/cjs/util/type-error.js +2 -0
- package/dist/esm/dialect/mysql/mysql-introspector.js +1 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +1 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +1 -1
- package/dist/esm/index.d.ts +1 -1
- 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/parser/binary-operation-parser.d.ts +1 -1
- package/dist/esm/parser/update-set-parser.d.ts +3 -3
- package/dist/esm/parser/update-set-parser.js +2 -2
- 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 +46 -3
- package/dist/esm/query-builder/insert-query-builder.js +45 -1
- package/dist/esm/query-builder/on-conflict-builder.d.ts +40 -2
- 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 +67 -3
- package/dist/esm/query-builder/update-query-builder.js +54 -2
- 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 +3 -35
- package/dist/esm/schema/alter-table-builder.js +4 -93
- 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/util/type-error.d.ts +3 -0
- package/dist/esm/util/type-error.js +2 -0
- package/package.json +2 -2
|
@@ -4,7 +4,7 @@ import { SelectExpression } from '../parser/select-parser.js';
|
|
|
4
4
|
import { InsertObject } from '../parser/insert-values-parser.js';
|
|
5
5
|
import { InsertQueryNode } from '../operation-node/insert-query-node.js';
|
|
6
6
|
import { MergePartial, SingleResultType } from '../util/type-utils.js';
|
|
7
|
-
import {
|
|
7
|
+
import { UpdateObject } from '../parser/update-set-parser.js';
|
|
8
8
|
import { Compilable } from '../util/compilable.js';
|
|
9
9
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
10
10
|
import { QueryId } from '../util/query-id.js';
|
|
@@ -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);
|
|
@@ -384,7 +385,7 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
384
385
|
* .onDuplicateKeyUpdate({ species: 'hamster' })
|
|
385
386
|
* ```
|
|
386
387
|
*/
|
|
387
|
-
onDuplicateKeyUpdate(updates:
|
|
388
|
+
onDuplicateKeyUpdate(updates: UpdateObject<DB, TB, TB>): InsertQueryBuilder<DB, TB, O>;
|
|
388
389
|
/**
|
|
389
390
|
* Allows you to return data from modified rows.
|
|
390
391
|
*
|
|
@@ -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
|
*/
|
|
@@ -4,7 +4,7 @@ import { OperationNodeSource } from '../operation-node/operation-node-source.js'
|
|
|
4
4
|
import { ComparisonOperatorExpression, OperandValueExpressionOrList, WhereGrouper } from '../parser/binary-operation-parser.js';
|
|
5
5
|
import { ExpressionOrFactory } from '../parser/expression-parser.js';
|
|
6
6
|
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
7
|
-
import {
|
|
7
|
+
import { UpdateObject } from '../parser/update-set-parser.js';
|
|
8
8
|
import { AnyColumn } from '../util/type-utils.js';
|
|
9
9
|
import { WhereInterface } from './where-interface.js';
|
|
10
10
|
export declare class OnConflictBuilder<DB, TB extends keyof DB> implements WhereInterface<DB, TB> {
|
|
@@ -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
|
*
|
|
@@ -387,7 +406,7 @@ export declare class OnConflictBuilder<DB, TB extends keyof DB> implements Where
|
|
|
387
406
|
* do update set "first_name" = $3
|
|
388
407
|
* ```
|
|
389
408
|
*/
|
|
390
|
-
doUpdateSet(updates:
|
|
409
|
+
doUpdateSet(updates: UpdateObject<OnConflictDatabase<DB, TB>, OnConflictTables<TB>, OnConflictTables<TB>>): OnConflictUpdateBuilder<OnConflictDatabase<DB, TB>, OnConflictTables<TB>>;
|
|
391
410
|
}
|
|
392
411
|
export interface OnConflictBuilderProps {
|
|
393
412
|
readonly onConflictNode: OnConflictNode;
|
|
@@ -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
|
}
|
|
@@ -19,6 +19,7 @@ import { Explainable, ExplainFormat } from '../util/explainable.js';
|
|
|
19
19
|
import { AliasedExpression, Expression } from '../expression/expression.js';
|
|
20
20
|
import { ComparisonOperatorExpression, HavingGrouper, OperandValueExpressionOrList, WhereGrouper } from '../parser/binary-operation-parser.js';
|
|
21
21
|
import { ExistsExpression } from '../parser/unary-operation-parser.js';
|
|
22
|
+
import { KyselyTypeError } from '../util/type-error.js';
|
|
22
23
|
export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, HavingInterface<DB, TB>, Expression<O>, Compilable<O>, Explainable {
|
|
23
24
|
#private;
|
|
24
25
|
constructor(props: SelectQueryBuilderProps);
|
|
@@ -1291,6 +1292,102 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1291
1292
|
* ```
|
|
1292
1293
|
*/
|
|
1293
1294
|
exceptAll(expression: Expression<O>): SelectQueryBuilder<DB, TB, O>;
|
|
1295
|
+
/**
|
|
1296
|
+
* Clears all select clauses from the query.
|
|
1297
|
+
*
|
|
1298
|
+
* ### Examples
|
|
1299
|
+
*
|
|
1300
|
+
* ```ts
|
|
1301
|
+
* db.selectFrom('person')
|
|
1302
|
+
* .select(['id', 'first_name'])
|
|
1303
|
+
* .clearSelect()
|
|
1304
|
+
* .select(['id','gender'])
|
|
1305
|
+
* ```
|
|
1306
|
+
*
|
|
1307
|
+
* The generated SQL(PostgreSQL):
|
|
1308
|
+
*
|
|
1309
|
+
* ```sql
|
|
1310
|
+
* select "id", "gender" from "person"
|
|
1311
|
+
* ```
|
|
1312
|
+
*/
|
|
1313
|
+
clearSelect(): SelectQueryBuilder<DB, TB, {}>;
|
|
1314
|
+
/**
|
|
1315
|
+
* Clears all where clauses from the query.
|
|
1316
|
+
*
|
|
1317
|
+
* ### Examples
|
|
1318
|
+
*
|
|
1319
|
+
* ```ts
|
|
1320
|
+
* db.selectFrom('person')
|
|
1321
|
+
* .selectAll()
|
|
1322
|
+
* .where('id','=',42)
|
|
1323
|
+
* .clearWhere()
|
|
1324
|
+
* ```
|
|
1325
|
+
*
|
|
1326
|
+
* The generated SQL(PostgreSQL):
|
|
1327
|
+
*
|
|
1328
|
+
* ```sql
|
|
1329
|
+
* select * from "person"
|
|
1330
|
+
* ```
|
|
1331
|
+
*/
|
|
1332
|
+
clearWhere(): SelectQueryBuilder<DB, TB, O>;
|
|
1333
|
+
/**
|
|
1334
|
+
* Clears limit clause from the query.
|
|
1335
|
+
*
|
|
1336
|
+
* ### Examples
|
|
1337
|
+
*
|
|
1338
|
+
* ```ts
|
|
1339
|
+
* db.selectFrom('person')
|
|
1340
|
+
* .selectAll()
|
|
1341
|
+
* .limit(10)
|
|
1342
|
+
* .clearLimit()
|
|
1343
|
+
* ```
|
|
1344
|
+
*
|
|
1345
|
+
* The generated SQL(PostgreSQL):
|
|
1346
|
+
*
|
|
1347
|
+
* ```sql
|
|
1348
|
+
* select * from "person"
|
|
1349
|
+
* ```
|
|
1350
|
+
*/
|
|
1351
|
+
clearLimit(): SelectQueryBuilder<DB, TB, O>;
|
|
1352
|
+
/**
|
|
1353
|
+
* Clears offset clause from the query.
|
|
1354
|
+
*
|
|
1355
|
+
* ### Examples
|
|
1356
|
+
*
|
|
1357
|
+
* ```ts
|
|
1358
|
+
* db.selectFrom('person')
|
|
1359
|
+
* .selectAll()
|
|
1360
|
+
* .limit(10)
|
|
1361
|
+
* .offset(20)
|
|
1362
|
+
* .clearOffset()
|
|
1363
|
+
* ```
|
|
1364
|
+
*
|
|
1365
|
+
* The generated SQL(PostgreSQL):
|
|
1366
|
+
*
|
|
1367
|
+
* ```sql
|
|
1368
|
+
* select * from "person" limit 10
|
|
1369
|
+
* ```
|
|
1370
|
+
*/
|
|
1371
|
+
clearOffset(): SelectQueryBuilder<DB, TB, O>;
|
|
1372
|
+
/**
|
|
1373
|
+
* Clears all `order by` clauses from the query.
|
|
1374
|
+
*
|
|
1375
|
+
* ### Examples
|
|
1376
|
+
*
|
|
1377
|
+
* ```ts
|
|
1378
|
+
* db.selectFrom('person')
|
|
1379
|
+
* .selectAll()
|
|
1380
|
+
* .orderBy('id')
|
|
1381
|
+
* .clearOrderBy()
|
|
1382
|
+
* ```
|
|
1383
|
+
*
|
|
1384
|
+
* The generated SQL(PostgreSQL):
|
|
1385
|
+
*
|
|
1386
|
+
* ```sql
|
|
1387
|
+
* select * from "person"
|
|
1388
|
+
* ```
|
|
1389
|
+
*/
|
|
1390
|
+
clearOrderBy(): SelectQueryBuilder<DB, TB, O>;
|
|
1294
1391
|
/**
|
|
1295
1392
|
* Simply calls the given function passing `this` as the only argument.
|
|
1296
1393
|
*
|
|
@@ -1299,7 +1396,7 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1299
1396
|
*
|
|
1300
1397
|
* ### Examples
|
|
1301
1398
|
*
|
|
1302
|
-
* The next example uses a helper
|
|
1399
|
+
* The next example uses a helper function `log` to log a query:
|
|
1303
1400
|
*
|
|
1304
1401
|
* ```ts
|
|
1305
1402
|
* function log<T extends Compilable>(qb: T): T {
|
|
@@ -1392,6 +1489,46 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
1392
1489
|
* don't support your use case.
|
|
1393
1490
|
*/
|
|
1394
1491
|
castTo<T>(): SelectQueryBuilder<DB, TB, T>;
|
|
1492
|
+
/**
|
|
1493
|
+
* Asserts that query's output row type equals the given type `T`.
|
|
1494
|
+
*
|
|
1495
|
+
* This method can be used to simplify excessively complex types to make typescript happy
|
|
1496
|
+
* and much faster.
|
|
1497
|
+
*
|
|
1498
|
+
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
|
|
1499
|
+
* for typescript and you get errors like this:
|
|
1500
|
+
*
|
|
1501
|
+
* ```
|
|
1502
|
+
* error TS2589: Type instantiation is excessively deep and possibly infinite.
|
|
1503
|
+
* ```
|
|
1504
|
+
*
|
|
1505
|
+
* In these case you can often use this method to help typescript a little bit. When you use this
|
|
1506
|
+
* method to assert the output type of a query, Kysely can drop the complex output type that
|
|
1507
|
+
* consists of multiple nested helper types and replace it with the simple asserted type.
|
|
1508
|
+
*
|
|
1509
|
+
* Using this method doesn't reduce type safety at all. You have to pass in a type that is
|
|
1510
|
+
* structurally equal to the current type.
|
|
1511
|
+
*
|
|
1512
|
+
* ### Examples
|
|
1513
|
+
*
|
|
1514
|
+
* ```ts
|
|
1515
|
+
* const result = await db
|
|
1516
|
+
* .with('first_and_last', (qb) => qb
|
|
1517
|
+
* .selectFrom('person')
|
|
1518
|
+
* .select(['first_name', 'last_name'])
|
|
1519
|
+
* .assertType<{ first_name: string, last_name: string }>()
|
|
1520
|
+
* )
|
|
1521
|
+
* .with('age', (qb) => qb
|
|
1522
|
+
* .selectFrom('person')
|
|
1523
|
+
* .select('age')
|
|
1524
|
+
* .assertType<{ age: number }>()
|
|
1525
|
+
* )
|
|
1526
|
+
* .selectFrom(['first_and_last', 'age'])
|
|
1527
|
+
* .selectAll()
|
|
1528
|
+
* .executeTakeFirstOrThrow()
|
|
1529
|
+
* ```
|
|
1530
|
+
*/
|
|
1531
|
+
assertType<T extends O>(): O extends T ? SelectQueryBuilder<DB, TB, T> : KyselyTypeError<`assertType() call failed: The type passed in is not equal to the output type of the query.`>;
|
|
1395
1532
|
/**
|
|
1396
1533
|
* Returns a copy of this SelectQueryBuilder instance with the given plugin installed.
|
|
1397
1534
|
*/
|
|
@@ -579,6 +579,109 @@ export class SelectQueryBuilder {
|
|
|
579
579
|
queryNode: SelectQueryNode.cloneWithSetOperation(this.#props.queryNode, parseSetOperation('except', expression, true)),
|
|
580
580
|
});
|
|
581
581
|
}
|
|
582
|
+
/**
|
|
583
|
+
* Clears all select clauses from the query.
|
|
584
|
+
*
|
|
585
|
+
* ### Examples
|
|
586
|
+
*
|
|
587
|
+
* ```ts
|
|
588
|
+
* db.selectFrom('person')
|
|
589
|
+
* .select(['id', 'first_name'])
|
|
590
|
+
* .clearSelect()
|
|
591
|
+
* .select(['id','gender'])
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* The generated SQL(PostgreSQL):
|
|
595
|
+
*
|
|
596
|
+
* ```sql
|
|
597
|
+
* select "id", "gender" from "person"
|
|
598
|
+
* ```
|
|
599
|
+
*/
|
|
600
|
+
clearSelect() {
|
|
601
|
+
return new SelectQueryBuilder({
|
|
602
|
+
...this.#props,
|
|
603
|
+
queryNode: SelectQueryNode.cloneWithoutSelections(this.#props.queryNode),
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
clearWhere() {
|
|
607
|
+
return new SelectQueryBuilder({
|
|
608
|
+
...this.#props,
|
|
609
|
+
queryNode: QueryNode.cloneWithoutWhere(this.#props.queryNode),
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Clears limit clause from the query.
|
|
614
|
+
*
|
|
615
|
+
* ### Examples
|
|
616
|
+
*
|
|
617
|
+
* ```ts
|
|
618
|
+
* db.selectFrom('person')
|
|
619
|
+
* .selectAll()
|
|
620
|
+
* .limit(10)
|
|
621
|
+
* .clearLimit()
|
|
622
|
+
* ```
|
|
623
|
+
*
|
|
624
|
+
* The generated SQL(PostgreSQL):
|
|
625
|
+
*
|
|
626
|
+
* ```sql
|
|
627
|
+
* select * from "person"
|
|
628
|
+
* ```
|
|
629
|
+
*/
|
|
630
|
+
clearLimit() {
|
|
631
|
+
return new SelectQueryBuilder({
|
|
632
|
+
...this.#props,
|
|
633
|
+
queryNode: SelectQueryNode.cloneWithoutLimit(this.#props.queryNode),
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* Clears offset clause from the query.
|
|
638
|
+
*
|
|
639
|
+
* ### Examples
|
|
640
|
+
*
|
|
641
|
+
* ```ts
|
|
642
|
+
* db.selectFrom('person')
|
|
643
|
+
* .selectAll()
|
|
644
|
+
* .limit(10)
|
|
645
|
+
* .offset(20)
|
|
646
|
+
* .clearOffset()
|
|
647
|
+
* ```
|
|
648
|
+
*
|
|
649
|
+
* The generated SQL(PostgreSQL):
|
|
650
|
+
*
|
|
651
|
+
* ```sql
|
|
652
|
+
* select * from "person" limit 10
|
|
653
|
+
* ```
|
|
654
|
+
*/
|
|
655
|
+
clearOffset() {
|
|
656
|
+
return new SelectQueryBuilder({
|
|
657
|
+
...this.#props,
|
|
658
|
+
queryNode: SelectQueryNode.cloneWithoutOffset(this.#props.queryNode),
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Clears all `order by` clauses from the query.
|
|
663
|
+
*
|
|
664
|
+
* ### Examples
|
|
665
|
+
*
|
|
666
|
+
* ```ts
|
|
667
|
+
* db.selectFrom('person')
|
|
668
|
+
* .selectAll()
|
|
669
|
+
* .orderBy('id')
|
|
670
|
+
* .clearOrderBy()
|
|
671
|
+
* ```
|
|
672
|
+
*
|
|
673
|
+
* The generated SQL(PostgreSQL):
|
|
674
|
+
*
|
|
675
|
+
* ```sql
|
|
676
|
+
* select * from "person"
|
|
677
|
+
* ```
|
|
678
|
+
*/
|
|
679
|
+
clearOrderBy() {
|
|
680
|
+
return new SelectQueryBuilder({
|
|
681
|
+
...this.#props,
|
|
682
|
+
queryNode: SelectQueryNode.cloneWithoutOrderBy(this.#props.queryNode),
|
|
683
|
+
});
|
|
684
|
+
}
|
|
582
685
|
/**
|
|
583
686
|
* Simply calls the given function passing `this` as the only argument.
|
|
584
687
|
*
|
|
@@ -587,7 +690,7 @@ export class SelectQueryBuilder {
|
|
|
587
690
|
*
|
|
588
691
|
* ### Examples
|
|
589
692
|
*
|
|
590
|
-
* The next example uses a helper
|
|
693
|
+
* The next example uses a helper function `log` to log a query:
|
|
591
694
|
*
|
|
592
695
|
* ```ts
|
|
593
696
|
* function log<T extends Compilable>(qb: T): T {
|
|
@@ -693,6 +796,48 @@ export class SelectQueryBuilder {
|
|
|
693
796
|
castTo() {
|
|
694
797
|
return new SelectQueryBuilder(this.#props);
|
|
695
798
|
}
|
|
799
|
+
/**
|
|
800
|
+
* Asserts that query's output row type equals the given type `T`.
|
|
801
|
+
*
|
|
802
|
+
* This method can be used to simplify excessively complex types to make typescript happy
|
|
803
|
+
* and much faster.
|
|
804
|
+
*
|
|
805
|
+
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
|
|
806
|
+
* for typescript and you get errors like this:
|
|
807
|
+
*
|
|
808
|
+
* ```
|
|
809
|
+
* error TS2589: Type instantiation is excessively deep and possibly infinite.
|
|
810
|
+
* ```
|
|
811
|
+
*
|
|
812
|
+
* In these case you can often use this method to help typescript a little bit. When you use this
|
|
813
|
+
* method to assert the output type of a query, Kysely can drop the complex output type that
|
|
814
|
+
* consists of multiple nested helper types and replace it with the simple asserted type.
|
|
815
|
+
*
|
|
816
|
+
* Using this method doesn't reduce type safety at all. You have to pass in a type that is
|
|
817
|
+
* structurally equal to the current type.
|
|
818
|
+
*
|
|
819
|
+
* ### Examples
|
|
820
|
+
*
|
|
821
|
+
* ```ts
|
|
822
|
+
* const result = await db
|
|
823
|
+
* .with('first_and_last', (qb) => qb
|
|
824
|
+
* .selectFrom('person')
|
|
825
|
+
* .select(['first_name', 'last_name'])
|
|
826
|
+
* .assertType<{ first_name: string, last_name: string }>()
|
|
827
|
+
* )
|
|
828
|
+
* .with('age', (qb) => qb
|
|
829
|
+
* .selectFrom('person')
|
|
830
|
+
* .select('age')
|
|
831
|
+
* .assertType<{ age: number }>()
|
|
832
|
+
* )
|
|
833
|
+
* .selectFrom(['first_and_last', 'age'])
|
|
834
|
+
* .selectAll()
|
|
835
|
+
* .executeTakeFirstOrThrow()
|
|
836
|
+
* ```
|
|
837
|
+
*/
|
|
838
|
+
assertType() {
|
|
839
|
+
return new SelectQueryBuilder(this.#props);
|
|
840
|
+
}
|
|
696
841
|
/**
|
|
697
842
|
* Returns a copy of this SelectQueryBuilder instance with the given plugin installed.
|
|
698
843
|
*/
|
|
@@ -7,7 +7,7 @@ import { ReturningRow } from '../parser/returning-parser.js';
|
|
|
7
7
|
import { ReferenceExpression } from '../parser/reference-parser.js';
|
|
8
8
|
import { MergePartial, Nullable, SingleResultType } from '../util/type-utils.js';
|
|
9
9
|
import { UpdateQueryNode } from '../operation-node/update-query-node.js';
|
|
10
|
-
import {
|
|
10
|
+
import { UpdateObject } from '../parser/update-set-parser.js';
|
|
11
11
|
import { Compilable } from '../util/compilable.js';
|
|
12
12
|
import { QueryExecutor } from '../query-executor/query-executor.js';
|
|
13
13
|
import { QueryId } from '../util/query-id.js';
|
|
@@ -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 UpdateQueryBuilder<DB, UT extends keyof 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: UpdateQueryBuilderProps);
|
|
@@ -408,6 +409,25 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
|
|
|
408
409
|
* Just like {@link whereExists} but creates an `or not exists` clause.
|
|
409
410
|
*/
|
|
410
411
|
orWhereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, 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(): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
411
431
|
/**
|
|
412
432
|
* Adds a from clause to the update query.
|
|
413
433
|
*
|
|
@@ -650,7 +670,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
|
|
|
650
670
|
* where "id" = $4
|
|
651
671
|
* ```
|
|
652
672
|
*/
|
|
653
|
-
set(row:
|
|
673
|
+
set(row: UpdateObject<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
654
674
|
/**
|
|
655
675
|
* Allows you to return data from modified rows.
|
|
656
676
|
*
|
|
@@ -725,7 +745,7 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
|
|
|
725
745
|
*
|
|
726
746
|
* ### Examples
|
|
727
747
|
*
|
|
728
|
-
* The next example uses a helper
|
|
748
|
+
* The next example uses a helper function `log` to log a query:
|
|
729
749
|
*
|
|
730
750
|
* ```ts
|
|
731
751
|
* function log<T extends Compilable>(qb: T): T {
|
|
@@ -784,6 +804,50 @@ export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyo
|
|
|
784
804
|
* don't support your use case.
|
|
785
805
|
*/
|
|
786
806
|
castTo<T>(): UpdateQueryBuilder<DB, UT, TB, T>;
|
|
807
|
+
/**
|
|
808
|
+
* Asserts that query's output row type equals the given type `T`.
|
|
809
|
+
*
|
|
810
|
+
* This method can be used to simplify excessively complex types to make typescript happy
|
|
811
|
+
* and much faster.
|
|
812
|
+
*
|
|
813
|
+
* Kysely uses complex type magic to achieve its type safety. This complexity is sometimes too much
|
|
814
|
+
* for typescript and you get errors like this:
|
|
815
|
+
*
|
|
816
|
+
* ```
|
|
817
|
+
* error TS2589: Type instantiation is excessively deep and possibly infinite.
|
|
818
|
+
* ```
|
|
819
|
+
*
|
|
820
|
+
* In these case you can often use this method to help typescript a little bit. When you use this
|
|
821
|
+
* method to assert the output type of a query, Kysely can drop the complex output type that
|
|
822
|
+
* consists of multiple nested helper types and replace it with the simple asserted type.
|
|
823
|
+
*
|
|
824
|
+
* Using this method doesn't reduce type safety at all. You have to pass in a type that is
|
|
825
|
+
* structurally equal to the current type.
|
|
826
|
+
*
|
|
827
|
+
* ### Examples
|
|
828
|
+
*
|
|
829
|
+
* ```ts
|
|
830
|
+
* const result = await db
|
|
831
|
+
* .with('updated_person', (qb) => qb
|
|
832
|
+
* .updateTable('person')
|
|
833
|
+
* .set(person)
|
|
834
|
+
* .where('id', '=', person.id)
|
|
835
|
+
* .returning('first_name')
|
|
836
|
+
* .assertType<{ first_name: string }>()
|
|
837
|
+
* )
|
|
838
|
+
* .with('updated_pet', (qb) => qb
|
|
839
|
+
* .updateTable('pet')
|
|
840
|
+
* .set(pet)
|
|
841
|
+
* .where('owner_id', '=', person.id)
|
|
842
|
+
* .returning(['name as pet_name', 'species'])
|
|
843
|
+
* .assertType<{ pet_name: string, species: Species }>()
|
|
844
|
+
* )
|
|
845
|
+
* .selectFrom(['updated_person', 'updated_pet'])
|
|
846
|
+
* .selectAll()
|
|
847
|
+
* .executeTakeFirstOrThrow()
|
|
848
|
+
* ```
|
|
849
|
+
*/
|
|
850
|
+
assertType<T extends O>(): O extends T ? UpdateQueryBuilder<DB, UT, TB, T> : KyselyTypeError<`assertType() call failed: The type passed in is not equal to the output type of the query.`>;
|
|
787
851
|
/**
|
|
788
852
|
* Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
|
|
789
853
|
*/
|