kysely 0.17.2 → 0.18.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 +2 -0
- package/dist/cjs/dialect/database-introspector.d.ts +13 -0
- package/dist/cjs/dialect/mysql/mysql-dialect-config.d.ts +19 -19
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +9 -1
- package/dist/cjs/dialect/mysql/mysql-dialect.js +11 -5
- package/dist/cjs/dialect/mysql/mysql-driver.d.ts +25 -3
- package/dist/cjs/dialect/mysql/mysql-driver.js +48 -35
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +11 -1
- package/dist/cjs/dialect/mysql/mysql-introspector.js +29 -7
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +9 -1
- package/dist/cjs/dialect/postgres/postgres-dialect.js +11 -5
- package/dist/cjs/dialect/postgres/postgres-driver.d.ts +25 -3
- package/dist/cjs/dialect/postgres/postgres-driver.js +37 -24
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +11 -1
- package/dist/cjs/dialect/postgres/postgres-introspector.js +15 -4
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +11 -1
- package/dist/cjs/dialect/sqlite/sqlite-introspector.js +11 -4
- package/dist/cjs/index-nodeless.js +5 -1
- package/dist/cjs/index.js +5 -1
- package/dist/cjs/migration/migrator.d.ts +44 -2
- package/dist/cjs/migration/migrator.js +77 -18
- package/dist/cjs/operation-node/alias-node.d.ts +2 -2
- package/dist/cjs/operation-node/alias-node.js +1 -2
- package/dist/cjs/operation-node/operation-node-transformer.js +1 -0
- package/dist/cjs/operation-node/update-query-node.d.ts +3 -0
- package/dist/cjs/operation-node/update-query-node.js +11 -2
- package/dist/cjs/parser/reference-parser.js +2 -1
- package/dist/cjs/parser/table-parser.js +2 -1
- package/dist/cjs/parser/update-set-parser.d.ts +3 -3
- package/dist/cjs/parser/with-parser.d.ts +2 -2
- package/dist/cjs/plugin/noop-plugin.d.ts +42 -0
- package/dist/cjs/plugin/noop-plugin.js +12 -0
- package/dist/cjs/query-builder/insert-query-builder.d.ts +1 -1
- package/dist/cjs/query-builder/on-conflict-builder.d.ts +1 -1
- package/dist/cjs/query-builder/select-query-builder.d.ts +3 -1
- package/dist/cjs/query-builder/select-query-builder.js +5 -5
- package/dist/cjs/query-builder/update-query-builder.d.ts +57 -28
- package/dist/cjs/query-builder/update-query-builder.js +7 -0
- package/dist/cjs/query-compiler/default-query-compiler.js +4 -0
- package/dist/cjs/query-creator.d.ts +10 -1
- package/dist/cjs/query-creator.js +18 -0
- package/dist/cjs/raw-builder/raw-builder.d.ts +32 -2
- package/dist/cjs/raw-builder/raw-builder.js +5 -26
- package/dist/cjs/schema/schema.d.ts +9 -0
- package/dist/cjs/schema/schema.js +12 -0
- package/dist/cjs/util/column-type.d.ts +9 -1
- package/dist/cjs/util/stack-trace-utils.d.ts +1 -0
- package/dist/cjs/util/stack-trace-utils.js +17 -0
- package/dist/esm/dialect/database-introspector.d.ts +13 -0
- package/dist/esm/dialect/mysql/mysql-dialect-config.d.ts +19 -19
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +9 -1
- package/dist/esm/dialect/mysql/mysql-dialect.js +11 -5
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +25 -3
- package/dist/esm/dialect/mysql/mysql-driver.js +48 -35
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +11 -1
- package/dist/esm/dialect/mysql/mysql-introspector.js +30 -8
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +9 -1
- package/dist/esm/dialect/postgres/postgres-dialect.js +11 -5
- package/dist/esm/dialect/postgres/postgres-driver.d.ts +25 -3
- package/dist/esm/dialect/postgres/postgres-driver.js +38 -25
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +11 -1
- package/dist/esm/dialect/postgres/postgres-introspector.js +16 -5
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +11 -1
- package/dist/esm/dialect/sqlite/sqlite-introspector.js +12 -5
- package/dist/esm/migration/migrator.d.ts +44 -2
- package/dist/esm/migration/migrator.js +76 -17
- package/dist/esm/operation-node/alias-node.d.ts +2 -2
- package/dist/esm/operation-node/alias-node.js +1 -2
- package/dist/esm/operation-node/operation-node-transformer.js +1 -0
- package/dist/esm/operation-node/update-query-node.d.ts +3 -0
- package/dist/esm/operation-node/update-query-node.js +11 -2
- package/dist/esm/parser/reference-parser.js +2 -1
- package/dist/esm/parser/table-parser.js +2 -1
- package/dist/esm/parser/update-set-parser.d.ts +3 -3
- package/dist/esm/parser/with-parser.d.ts +2 -2
- package/dist/esm/plugin/noop-plugin.d.ts +42 -0
- package/dist/esm/plugin/noop-plugin.js +9 -0
- package/dist/esm/query-builder/insert-query-builder.d.ts +1 -1
- package/dist/esm/query-builder/on-conflict-builder.d.ts +1 -1
- package/dist/esm/query-builder/select-query-builder.d.ts +3 -1
- package/dist/esm/query-builder/select-query-builder.js +5 -5
- package/dist/esm/query-builder/update-query-builder.d.ts +57 -28
- package/dist/esm/query-builder/update-query-builder.js +7 -0
- package/dist/esm/query-compiler/default-query-compiler.js +4 -0
- package/dist/esm/query-creator.d.ts +10 -1
- package/dist/esm/query-creator.js +18 -0
- package/dist/esm/raw-builder/raw-builder.d.ts +32 -2
- package/dist/esm/raw-builder/raw-builder.js +5 -26
- package/dist/esm/schema/schema.d.ts +9 -0
- package/dist/esm/schema/schema.js +12 -0
- package/dist/esm/util/column-type.d.ts +9 -1
- package/dist/esm/util/stack-trace-utils.d.ts +1 -0
- package/dist/esm/util/stack-trace-utils.js +14 -0
- package/package.json +9 -9
|
@@ -19,7 +19,7 @@ import { JoinInterface } from './join-interface.js';
|
|
|
19
19
|
import { ReturningInterface } from './returning-interface.js';
|
|
20
20
|
import { NoResultErrorConstructor } from './no-result-error.js';
|
|
21
21
|
import { Selectable } from '../util/column-type.js';
|
|
22
|
-
export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, JoinInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable {
|
|
22
|
+
export declare class UpdateQueryBuilder<DB, UT extends keyof DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, JoinInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable {
|
|
23
23
|
#private;
|
|
24
24
|
constructor(props: UpdateQueryBuilderProps);
|
|
25
25
|
/**
|
|
@@ -206,9 +206,9 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
206
206
|
* .execute()
|
|
207
207
|
* ```
|
|
208
208
|
*/
|
|
209
|
-
where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, TB, O>;
|
|
210
|
-
where(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
211
|
-
where(raw: AnyRawBuilder): UpdateQueryBuilder<DB, TB, O>;
|
|
209
|
+
where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
210
|
+
where(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
211
|
+
where(raw: AnyRawBuilder): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
212
212
|
/**
|
|
213
213
|
* Adds a `where` clause where both sides of the operator are references
|
|
214
214
|
* to columns.
|
|
@@ -260,7 +260,7 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
260
260
|
* ) as "pet_name"
|
|
261
261
|
* from "person"
|
|
262
262
|
*/
|
|
263
|
-
whereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
263
|
+
whereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
264
264
|
/**
|
|
265
265
|
* Adds an `or where` clause to the query. Otherwise works just like {@link where}.
|
|
266
266
|
*
|
|
@@ -324,15 +324,15 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
324
324
|
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
325
325
|
* ```
|
|
326
326
|
*/
|
|
327
|
-
orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, TB, O>;
|
|
328
|
-
orWhere(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
329
|
-
orWhere(raw: AnyRawBuilder): UpdateQueryBuilder<DB, TB, O>;
|
|
327
|
+
orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
328
|
+
orWhere(grouper: WhereGrouper<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
329
|
+
orWhere(raw: AnyRawBuilder): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
330
330
|
/**
|
|
331
331
|
* Adds an `or where` clause to the query. Otherwise works just like {@link whereRef}.
|
|
332
332
|
*
|
|
333
333
|
* Also see {@link orWhere} and {@link where}.
|
|
334
334
|
*/
|
|
335
|
-
orWhereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
335
|
+
orWhereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
336
336
|
/**
|
|
337
337
|
* Adds a `where exists` clause to the query.
|
|
338
338
|
*
|
|
@@ -393,19 +393,48 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
393
393
|
* )
|
|
394
394
|
* ```
|
|
395
395
|
*/
|
|
396
|
-
whereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
396
|
+
whereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
397
397
|
/**
|
|
398
398
|
* Just like {@link whereExists} but creates a `not exists` clause.
|
|
399
399
|
*/
|
|
400
|
-
whereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
400
|
+
whereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
401
401
|
/**
|
|
402
402
|
* Just like {@link whereExists} but creates a `or exists` clause.
|
|
403
403
|
*/
|
|
404
|
-
orWhereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
404
|
+
orWhereExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
405
405
|
/**
|
|
406
406
|
* Just like {@link whereExists} but creates a `or not exists` clause.
|
|
407
407
|
*/
|
|
408
|
-
orWhereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
408
|
+
orWhereNotExists(arg: ExistsExpression<DB, TB>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
409
|
+
/**
|
|
410
|
+
* Adds a from clause to the update query.
|
|
411
|
+
*
|
|
412
|
+
* This is supported only on some databases like PostgreSQL.
|
|
413
|
+
*
|
|
414
|
+
* The API is the same as {@link QueryCreator.selectFrom}.
|
|
415
|
+
*
|
|
416
|
+
* ### Examples
|
|
417
|
+
*
|
|
418
|
+
* ```ts
|
|
419
|
+
* db.updateTable('person')
|
|
420
|
+
* .from('pet')
|
|
421
|
+
* .set({
|
|
422
|
+
* first_name: (eb) => eb.ref('pet.name')
|
|
423
|
+
* })
|
|
424
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
425
|
+
* ```
|
|
426
|
+
*
|
|
427
|
+
* The generated SQL (PostgreSQL):
|
|
428
|
+
*
|
|
429
|
+
* ```sql
|
|
430
|
+
* update "person"
|
|
431
|
+
* set "first_name" = "pet"."name"
|
|
432
|
+
* from "pet"
|
|
433
|
+
* where "pet"."owner_id" = "person"."id"
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
from<TE extends TableExpression<DB, TB>>(table: TE): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
437
|
+
from<TE extends TableExpression<DB, TB>>(table: TE[]): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
409
438
|
/**
|
|
410
439
|
* Joins another table to the query using an inner join.
|
|
411
440
|
*
|
|
@@ -515,23 +544,23 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
515
544
|
* on "doggos"."owner_id" = "person"."id"
|
|
516
545
|
* ```
|
|
517
546
|
*/
|
|
518
|
-
innerJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
519
|
-
innerJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
547
|
+
innerJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
548
|
+
innerJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<TableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
520
549
|
/**
|
|
521
550
|
* Just like {@link innerJoin} but adds a left join nstead of an inner join.
|
|
522
551
|
*/
|
|
523
|
-
leftJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
524
|
-
leftJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
552
|
+
leftJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
553
|
+
leftJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
525
554
|
/**
|
|
526
555
|
* Just like {@link innerJoin} but adds a right join instead of an inner join.
|
|
527
556
|
*/
|
|
528
|
-
rightJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
529
|
-
rightJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
557
|
+
rightJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
558
|
+
rightJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
530
559
|
/**
|
|
531
560
|
* Just like {@link innerJoin} but adds a full join instead of an inner join.
|
|
532
561
|
*/
|
|
533
|
-
fullJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
534
|
-
fullJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
562
|
+
fullJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
563
|
+
fullJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): UpdateQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, UT, TableExpressionTables<DB, TB, TE>, O>;
|
|
535
564
|
/**
|
|
536
565
|
* Sets the values to update for an {@link Kysely.updateTable | update} query.
|
|
537
566
|
*
|
|
@@ -619,7 +648,7 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
619
648
|
* where "id" = $4
|
|
620
649
|
* ```
|
|
621
650
|
*/
|
|
622
|
-
set(row: MutationObject<DB, TB>): UpdateQueryBuilder<DB, TB, O>;
|
|
651
|
+
set(row: MutationObject<DB, TB, UT>): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
623
652
|
/**
|
|
624
653
|
* Allows you to return data from modified rows.
|
|
625
654
|
*
|
|
@@ -679,13 +708,13 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
679
708
|
* .executeTakeFirst()
|
|
680
709
|
* ```
|
|
681
710
|
*/
|
|
682
|
-
returning<SE extends SelectExpression<DB, TB>>(selections: ReadonlyArray<SE>): UpdateQueryBuilder<DB, TB, ReturningRow<DB, TB, O, SE>>;
|
|
683
|
-
returning<SE extends SelectExpression<DB, TB>>(selection: SE): UpdateQueryBuilder<DB, TB, ReturningRow<DB, TB, O, SE>>;
|
|
711
|
+
returning<SE extends SelectExpression<DB, TB>>(selections: ReadonlyArray<SE>): UpdateQueryBuilder<DB, UT, TB, ReturningRow<DB, TB, O, SE>>;
|
|
712
|
+
returning<SE extends SelectExpression<DB, TB>>(selection: SE): UpdateQueryBuilder<DB, UT, TB, ReturningRow<DB, TB, O, SE>>;
|
|
684
713
|
/**
|
|
685
714
|
* Adds a `returning *` to an insert/update/delete query on databases
|
|
686
715
|
* that support `returning` such as PostgreSQL.
|
|
687
716
|
*/
|
|
688
|
-
returningAll(): UpdateQueryBuilder<DB, TB, Selectable<DB[TB]>>;
|
|
717
|
+
returningAll(): UpdateQueryBuilder<DB, UT, TB, Selectable<DB[TB]>>;
|
|
689
718
|
/**
|
|
690
719
|
* Simply calls the given function passing `this` as the only argument.
|
|
691
720
|
*
|
|
@@ -745,18 +774,18 @@ export declare class UpdateQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
745
774
|
* }
|
|
746
775
|
* ```
|
|
747
776
|
*/
|
|
748
|
-
if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, TB, O2>): UpdateQueryBuilder<DB, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
|
|
777
|
+
if<O2>(condition: boolean, func: (qb: this) => UpdateQueryBuilder<DB, UT, TB, O2>): UpdateQueryBuilder<DB, UT, TB, O2 extends UpdateResult ? UpdateResult : O extends UpdateResult ? Partial<O2> : MergePartial<O, O2>>;
|
|
749
778
|
/**
|
|
750
779
|
* Change the output type of the query.
|
|
751
780
|
*
|
|
752
781
|
* You should only use this method as the last resort if the types
|
|
753
782
|
* don't support your use case.
|
|
754
783
|
*/
|
|
755
|
-
castTo<T>(): UpdateQueryBuilder<DB, TB, T>;
|
|
784
|
+
castTo<T>(): UpdateQueryBuilder<DB, UT, TB, T>;
|
|
756
785
|
/**
|
|
757
786
|
* Returns a copy of this UpdateQueryBuilder instance with the given plugin installed.
|
|
758
787
|
*/
|
|
759
|
-
withPlugin(plugin: KyselyPlugin): UpdateQueryBuilder<DB, TB, O>;
|
|
788
|
+
withPlugin(plugin: KyselyPlugin): UpdateQueryBuilder<DB, UT, TB, O>;
|
|
760
789
|
toOperationNode(): UpdateQueryNode;
|
|
761
790
|
compile(): CompiledQuery;
|
|
762
791
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="./update-query-builder.d.ts" />
|
|
2
2
|
import { parseJoin, } from '../parser/join-parser.js';
|
|
3
|
+
import { parseTableExpressionOrList, } from '../parser/table-parser.js';
|
|
3
4
|
import { parseSelectExpressionOrList, parseSelectAll, } from '../parser/select-parser.js';
|
|
4
5
|
import { parseExistFilter, parseReferenceFilter, parseWhereFilter, parseNotExistFilter, } from '../parser/filter-parser.js';
|
|
5
6
|
import { QueryNode } from '../operation-node/query-node.js';
|
|
@@ -62,6 +63,12 @@ export class UpdateQueryBuilder {
|
|
|
62
63
|
queryNode: QueryNode.cloneWithOrWhere(this.#props.queryNode, parseNotExistFilter(arg)),
|
|
63
64
|
});
|
|
64
65
|
}
|
|
66
|
+
from(from) {
|
|
67
|
+
return new UpdateQueryBuilder({
|
|
68
|
+
...this.#props,
|
|
69
|
+
queryNode: UpdateQueryNode.cloneWithFromItems(this.#props.queryNode, parseTableExpressionOrList(from)),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
65
72
|
innerJoin(...args) {
|
|
66
73
|
return new UpdateQueryBuilder({
|
|
67
74
|
...this.#props,
|
|
@@ -425,6 +425,10 @@ export class DefaultQueryCompiler extends OperationNodeVisitor {
|
|
|
425
425
|
if (node.updates) {
|
|
426
426
|
this.compileList(node.updates);
|
|
427
427
|
}
|
|
428
|
+
if (node.from) {
|
|
429
|
+
this.append(' ');
|
|
430
|
+
this.visitNode(node.from);
|
|
431
|
+
}
|
|
428
432
|
if (node.joins) {
|
|
429
433
|
this.append(' ');
|
|
430
434
|
this.compileList(node.joins, ' ');
|
|
@@ -9,6 +9,7 @@ import { WithNode } from './operation-node/with-node.js';
|
|
|
9
9
|
import { InsertResult } from './query-builder/insert-result.js';
|
|
10
10
|
import { DeleteResult } from './query-builder/delete-result.js';
|
|
11
11
|
import { UpdateResult } from './query-builder/update-result.js';
|
|
12
|
+
import { KyselyPlugin } from './plugin/kysely-plugin.js';
|
|
12
13
|
export declare class QueryCreator<DB> {
|
|
13
14
|
#private;
|
|
14
15
|
constructor(props: QueryCreatorProps);
|
|
@@ -203,7 +204,7 @@ export declare class QueryCreator<DB> {
|
|
|
203
204
|
* console.log(result.numUpdatedRows)
|
|
204
205
|
* ```
|
|
205
206
|
*/
|
|
206
|
-
updateTable<TR extends TableReference<DB>>(table: TR): UpdateQueryBuilder<TableExpressionDatabase<DB, TR>, TableExpressionTables<DB, never, TR>, UpdateResult>;
|
|
207
|
+
updateTable<TR extends TableReference<DB>>(table: TR): UpdateQueryBuilder<TableExpressionDatabase<DB, TR>, TableExpressionTables<DB, never, TR>, TableExpressionTables<DB, never, TR>, UpdateResult>;
|
|
207
208
|
/**
|
|
208
209
|
* Creates a `with` query (Common Table Expression).
|
|
209
210
|
*
|
|
@@ -252,6 +253,14 @@ export declare class QueryCreator<DB> {
|
|
|
252
253
|
* See the {@link with} method for examples and more documentation.
|
|
253
254
|
*/
|
|
254
255
|
withRecursive<N extends string, E extends RecursiveCommonTableExpression<DB, N>>(name: N, expression: E): QueryCreatorWithCommonTableExpression<DB, N, E>;
|
|
256
|
+
/**
|
|
257
|
+
* Returns a copy of this query creator instance with the given plugin installed.
|
|
258
|
+
*/
|
|
259
|
+
withPlugin(plugin: KyselyPlugin): QueryCreator<DB>;
|
|
260
|
+
/**
|
|
261
|
+
* Returns a copy of this query creator instance without any plugins.
|
|
262
|
+
*/
|
|
263
|
+
withoutPlugins(): QueryCreator<DB>;
|
|
255
264
|
/**
|
|
256
265
|
* Sets the schema to be used for all table references that don't explicitly
|
|
257
266
|
* specify a schema.
|
|
@@ -190,6 +190,24 @@ export class QueryCreator {
|
|
|
190
190
|
: WithNode.create(cte, { recursive: true }),
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Returns a copy of this query creator instance with the given plugin installed.
|
|
195
|
+
*/
|
|
196
|
+
withPlugin(plugin) {
|
|
197
|
+
return new QueryCreator({
|
|
198
|
+
...this.#props,
|
|
199
|
+
executor: this.#props.executor.withPlugin(plugin),
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Returns a copy of this query creator instance without any plugins.
|
|
204
|
+
*/
|
|
205
|
+
withoutPlugins() {
|
|
206
|
+
return new QueryCreator({
|
|
207
|
+
...this.#props,
|
|
208
|
+
executor: this.#props.executor.withoutPlugins(),
|
|
209
|
+
});
|
|
210
|
+
}
|
|
193
211
|
/**
|
|
194
212
|
* Sets the schema to be used for all table references that don't explicitly
|
|
195
213
|
* specify a schema.
|
|
@@ -5,6 +5,7 @@ import { RawNode } from '../operation-node/raw-node.js';
|
|
|
5
5
|
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
6
6
|
import { QueryExecutorProvider } from '../query-executor/query-executor-provider.js';
|
|
7
7
|
import { QueryId } from '../util/query-id.js';
|
|
8
|
+
import { AnyRawBuilder } from '../util/type-utils.js';
|
|
8
9
|
/**
|
|
9
10
|
* An instance of this class can be used to create raw SQL snippets or queries.
|
|
10
11
|
*
|
|
@@ -38,8 +39,37 @@ export declare class RawBuilder<O = unknown> implements OperationNodeSource {
|
|
|
38
39
|
* select concat(first_name, ' ', last_name) as "full_name"
|
|
39
40
|
* from "person"
|
|
40
41
|
* ```
|
|
42
|
+
*
|
|
43
|
+
* You can also pass in a raw SQL snippet but in that case you must
|
|
44
|
+
* provide the alias as the only type argument:
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* const values = sql<{ a: number, b: string }>`(values (1, 'foo'))`
|
|
48
|
+
*
|
|
49
|
+
* // The alias is `t(a, b)` which specifies the column names
|
|
50
|
+
* // in addition to the table name. We must tell kysely that
|
|
51
|
+
* // columns of the table can be referenced through `t`
|
|
52
|
+
* // by providing an explicit type argument.
|
|
53
|
+
* const aliasedValues = values.as<'t'>(sql`t(a, b)`)
|
|
54
|
+
*
|
|
55
|
+
* await db
|
|
56
|
+
* .insertInto('person')
|
|
57
|
+
* .columns(['first_name', 'last_name'])
|
|
58
|
+
* .expression(
|
|
59
|
+
* db.selectFrom(aliasedValues).select(['t.a', 't.b'])
|
|
60
|
+
* )
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* The generated SQL (PostgreSQL):
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* insert into "person" ("first_name", "last_name")
|
|
67
|
+
* from (values (1, 'foo')) as t(a, b)
|
|
68
|
+
* select "t"."a", "t"."b"
|
|
69
|
+
* ```
|
|
41
70
|
*/
|
|
42
71
|
as<A extends string>(alias: A): AliasedRawBuilder<O, A>;
|
|
72
|
+
as<A extends string = never>(alias: AnyRawBuilder): AliasedRawBuilder<O, A>;
|
|
43
73
|
/**
|
|
44
74
|
* Change the output type of the raw expression.
|
|
45
75
|
*
|
|
@@ -67,9 +97,9 @@ export declare class AliasedRawBuilder<O = unknown, A extends string = never> im
|
|
|
67
97
|
* which causes this type to be equal to AliasedRawBuilder with any A
|
|
68
98
|
* as long as O is the same.
|
|
69
99
|
*/
|
|
70
|
-
protected get alias(): A;
|
|
100
|
+
protected get alias(): A | AnyRawBuilder;
|
|
71
101
|
toOperationNode(): AliasNode;
|
|
72
|
-
constructor(rawBuilder: RawBuilder<O>, alias: A);
|
|
102
|
+
constructor(rawBuilder: RawBuilder<O>, alias: A | AnyRawBuilder);
|
|
73
103
|
}
|
|
74
104
|
export interface RawBuilderProps {
|
|
75
105
|
readonly queryId: QueryId;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference types="./raw-builder.d.ts" />
|
|
2
2
|
import { AliasNode } from '../operation-node/alias-node.js';
|
|
3
|
+
import { isOperationNodeSource, } from '../operation-node/operation-node-source.js';
|
|
3
4
|
import { preventAwait } from '../util/prevent-await.js';
|
|
4
5
|
import { freeze } from '../util/object-utils.js';
|
|
5
6
|
import { NOOP_QUERY_EXECUTOR } from '../query-executor/noop-query-executor.js';
|
|
7
|
+
import { IdentifierNode } from '../operation-node/identifier-node.js';
|
|
6
8
|
/**
|
|
7
9
|
* An instance of this class can be used to create raw SQL snippets or queries.
|
|
8
10
|
*
|
|
@@ -14,31 +16,6 @@ export class RawBuilder {
|
|
|
14
16
|
constructor(props) {
|
|
15
17
|
this.#props = freeze(props);
|
|
16
18
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Returns an aliased version of the SQL expression.
|
|
19
|
-
*
|
|
20
|
-
* In addition to slapping `as "the_alias"` to the end of the SQL,
|
|
21
|
-
* this method also provides strict typing:
|
|
22
|
-
*
|
|
23
|
-
* ```ts
|
|
24
|
-
* const result = await db
|
|
25
|
-
* .selectFrom('person')
|
|
26
|
-
* .select(
|
|
27
|
-
* sql<string>`concat(first_name, ' ', last_name)`.as('full_name')
|
|
28
|
-
* )
|
|
29
|
-
* .executeTakeFirstOrThrow()
|
|
30
|
-
*
|
|
31
|
-
* // `full_name: string` field exists in the result type.
|
|
32
|
-
* console.log(result.full_name)
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* The generated SQL (PostgreSQL):
|
|
36
|
-
*
|
|
37
|
-
* ```ts
|
|
38
|
-
* select concat(first_name, ' ', last_name) as "full_name"
|
|
39
|
-
* from "person"
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
19
|
as(alias) {
|
|
43
20
|
return new AliasedRawBuilder(this, alias);
|
|
44
21
|
}
|
|
@@ -100,7 +77,9 @@ export class AliasedRawBuilder {
|
|
|
100
77
|
return this.#alias;
|
|
101
78
|
}
|
|
102
79
|
toOperationNode() {
|
|
103
|
-
return AliasNode.create(this.#rawBuilder.toOperationNode(), this.#alias)
|
|
80
|
+
return AliasNode.create(this.#rawBuilder.toOperationNode(), isOperationNodeSource(this.#alias)
|
|
81
|
+
? this.#alias.toOperationNode()
|
|
82
|
+
: IdentifierNode.create(this.#alias));
|
|
104
83
|
}
|
|
105
84
|
constructor(rawBuilder, alias) {
|
|
106
85
|
this.#rawBuilder = rawBuilder;
|
|
@@ -8,6 +8,7 @@ import { DropSchemaBuilder } from './drop-schema-builder.js';
|
|
|
8
8
|
import { DropTableBuilder } from './drop-table-builder.js';
|
|
9
9
|
import { CreateViewBuilder } from './create-view-builder.js';
|
|
10
10
|
import { DropViewBuilder } from './drop-view-builder.js';
|
|
11
|
+
import { KyselyPlugin } from '../plugin/kysely-plugin.js';
|
|
11
12
|
/**
|
|
12
13
|
* Provides methods for building database schema.
|
|
13
14
|
*/
|
|
@@ -169,6 +170,14 @@ export declare class SchemaModule {
|
|
|
169
170
|
* ```
|
|
170
171
|
*/
|
|
171
172
|
dropView(viewName: string): DropViewBuilder;
|
|
173
|
+
/**
|
|
174
|
+
* Returns a copy of this schema module with the given plugin installed.
|
|
175
|
+
*/
|
|
176
|
+
withPlugin(plugin: KyselyPlugin): SchemaModule;
|
|
177
|
+
/**
|
|
178
|
+
* Returns a copy of this schema module without any plugins.
|
|
179
|
+
*/
|
|
180
|
+
withoutPlugins(): SchemaModule;
|
|
172
181
|
/**
|
|
173
182
|
* See {@link QueryCreator.withSchema}
|
|
174
183
|
*/
|
|
@@ -237,6 +237,18 @@ export class SchemaModule {
|
|
|
237
237
|
dropViewNode: DropViewNode.create(viewName),
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Returns a copy of this schema module with the given plugin installed.
|
|
242
|
+
*/
|
|
243
|
+
withPlugin(plugin) {
|
|
244
|
+
return new SchemaModule(this.#executor.withPlugin(plugin));
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Returns a copy of this schema module without any plugins.
|
|
248
|
+
*/
|
|
249
|
+
withoutPlugins() {
|
|
250
|
+
return new SchemaModule(this.#executor.withoutPlugins());
|
|
251
|
+
}
|
|
240
252
|
/**
|
|
241
253
|
* See {@link QueryCreator.withSchema}
|
|
242
254
|
*/
|
|
@@ -43,13 +43,21 @@ export declare type ColumnType<SelectType, InsertType = SelectType, UpdateType =
|
|
|
43
43
|
* is the same for all selects, inserts and updates but the
|
|
44
44
|
* column is optional for inserts and updates.
|
|
45
45
|
*
|
|
46
|
-
*
|
|
46
|
+
* The implementation:
|
|
47
47
|
*
|
|
48
48
|
* ```ts
|
|
49
|
+
* // The update type is `S` instead of `S | undefined` because
|
|
50
|
+
* // updates are always optional --> no need to specify optionality.
|
|
49
51
|
* type Generated<S> = ColumnType<S, S | undefined, S>
|
|
50
52
|
* ```
|
|
51
53
|
*/
|
|
52
54
|
export declare type Generated<S> = ColumnType<S, S | undefined, S>;
|
|
55
|
+
/**
|
|
56
|
+
* A shortcut for defining columns that are only database-generated
|
|
57
|
+
* (like postgres GENERATED ALWAYS AS IDENTITY). No insert/update
|
|
58
|
+
* is allowed.
|
|
59
|
+
*/
|
|
60
|
+
export declare type GeneratedAlways<S> = ColumnType<S, never, never>;
|
|
53
61
|
/**
|
|
54
62
|
* Evaluates to `K` if `T` can be `null` or `undefined`.
|
|
55
63
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function extendStackTrace(err: unknown, stackError: Error): unknown;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="./stack-trace-utils.d.ts" />
|
|
2
|
+
import { isObject, isString } from './object-utils.js';
|
|
3
|
+
export function extendStackTrace(err, stackError) {
|
|
4
|
+
if (isStackHolder(err) && stackError.stack) {
|
|
5
|
+
// Remove the first line that just says `Error`.
|
|
6
|
+
const stackExtension = stackError.stack.split('\n').slice(1).join('\n');
|
|
7
|
+
err.stack += `\n${stackExtension}`;
|
|
8
|
+
return err;
|
|
9
|
+
}
|
|
10
|
+
return err;
|
|
11
|
+
}
|
|
12
|
+
function isStackHolder(obj) {
|
|
13
|
+
return isObject(obj) && isString(obj.stack);
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kysely",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.1",
|
|
4
4
|
"description": "Type safe SQL query builder",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -48,21 +48,21 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/better-sqlite3": "^7.5.0",
|
|
51
|
-
"@types/chai": "^4.3.
|
|
51
|
+
"@types/chai": "^4.3.1",
|
|
52
52
|
"@types/chai-subset": "^1.3.3",
|
|
53
53
|
"@types/mocha": "^9.1.0",
|
|
54
54
|
"@types/pg": "^8.6.5",
|
|
55
|
-
"better-sqlite3": "^7.5.
|
|
55
|
+
"better-sqlite3": "^7.5.1",
|
|
56
56
|
"chai": "^4.3.6",
|
|
57
57
|
"chai-subset": "^1.6.0",
|
|
58
|
-
"esbuild": "^0.14.
|
|
58
|
+
"esbuild": "^0.14.36",
|
|
59
59
|
"mocha": "^9.2.2",
|
|
60
60
|
"mysql2": "^2.3.3",
|
|
61
61
|
"pg": "^8.7.3",
|
|
62
|
-
"playwright": "^1.
|
|
63
|
-
"prettier": "^2.6.
|
|
64
|
-
"tsd": "^0.
|
|
65
|
-
"typedoc": "^0.22.
|
|
66
|
-
"typescript": "4.6.
|
|
62
|
+
"playwright": "^1.21.0",
|
|
63
|
+
"prettier": "^2.6.2",
|
|
64
|
+
"tsd": "^0.20.0",
|
|
65
|
+
"typedoc": "^0.22.15",
|
|
66
|
+
"typescript": "4.6.3"
|
|
67
67
|
}
|
|
68
68
|
}
|