orchid-orm 1.58.9 → 1.59.0
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/dist/index.d.ts +29 -29
- package/dist/index.js +39 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -109
- package/dist/index.mjs.map +1 -1
- package/dist/migrations/node-postgres.js +4 -6
- package/dist/migrations/node-postgres.js.map +1 -1
- package/dist/migrations/node-postgres.mjs +4 -6
- package/dist/migrations/node-postgres.mjs.map +1 -1
- package/dist/migrations/postgres-js.js +4 -6
- package/dist/migrations/postgres-js.js.map +1 -1
- package/dist/migrations/postgres-js.mjs +4 -6
- package/dist/migrations/postgres-js.mjs.map +1 -1
- package/dist/node-postgres.d.ts +1 -1
- package/dist/postgres-js.d.ts +1 -1
- package/package.json +6 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Column, TableData, ColumnsShape, Query, SelectableFromShape, CreateManyMethodsNames, CreateData, AddQueryDefaults, RelationConfigBase, QueryTake, QueryTakeOptional, EmptyObject, UpdateData, WhereArg, CreateMethodsNames, MaybeArray, JoinQueryMethod, DeleteMethodsNames, Db, IsolationLevel, TransactionOptions, AfterCommitStandaloneHook, AdapterBase, FromArg, FromResult, DbSharedOptions, RelationsBase, ShapeColumnPrimaryKeys, ShapeUniqueColumns, TableDataItemsUniqueColumns, TableDataItemsUniqueColumnTuples, UniqueConstraints, TableDataItemsUniqueConstraints, ComputedColumnsFromOptions, MapTableScopesOption, TableDataItem, ComputedOptionsFactory, RecordUnknown, ShallowSimplify, ComputedOptionsConfig, QueryOrExpression, QueryData, IsQuery, TableDataFn, DbTableOptionScopes, CoreQueryScopes, ColumnSchemaConfig, StaticSQLArgs, RawSQL, DynamicSQLArg, DynamicRawSQL, DefaultSchemaConfig, DefaultColumnTypes, QueryBeforeHookInternal, QueryAfterHook, AfterHook, WhereResult, MergeQuery, QueryReturnType } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
3
|
|
|
4
|
-
interface RelationRefsOptions<Column extends PropertyKey = string, Shape extends
|
|
4
|
+
interface RelationRefsOptions<Column extends PropertyKey = string, Shape extends Column.Shape.QueryInit = Column.Shape.QueryInit> {
|
|
5
5
|
required?: boolean;
|
|
6
6
|
columns: Column[];
|
|
7
7
|
references: (keyof Shape)[];
|
|
8
8
|
foreignKey?: boolean | TableData.References.Options;
|
|
9
|
-
on?:
|
|
9
|
+
on?: ColumnsShape.InputPartial<Shape>;
|
|
10
10
|
}
|
|
11
11
|
interface RelationThroughOptions<Through extends PropertyKey = string, Source extends PropertyKey = string> {
|
|
12
12
|
through: Through;
|
|
@@ -20,7 +20,7 @@ interface HasOne extends RelationThunkBase {
|
|
|
20
20
|
interface RelationHasOneThroughOptions<Through extends string, Source extends string> extends RelationThroughOptions<Through, Source> {
|
|
21
21
|
required?: boolean;
|
|
22
22
|
}
|
|
23
|
-
type HasOneOptions<Columns extends
|
|
23
|
+
type HasOneOptions<Columns extends Column.Shape.QueryInit = Column.Shape.QueryInit, Related extends TableClass = TableClass, Through extends string = string, Source extends string = string> = RelationRefsOptions<keyof Columns, InstanceType<Related>['columns']['shape']> | RelationHasOneThroughOptions<Through, Source>;
|
|
24
24
|
type HasOneParams<T extends RelationConfigSelf, Relation extends RelationThunkBase> = Relation['options'] extends RelationRefsOptions ? {
|
|
25
25
|
[Name in Relation['options']['columns'][number]]: T['columns']['shape'][Name]['type'];
|
|
26
26
|
} : Relation['options'] extends RelationThroughOptions ? RelationConfigParams<T, T['relations'][Relation['options']['through']]> : never;
|
|
@@ -137,12 +137,12 @@ interface BelongsTo extends RelationThunkBase {
|
|
|
137
137
|
type: 'belongsTo';
|
|
138
138
|
options: BelongsToOptions;
|
|
139
139
|
}
|
|
140
|
-
interface BelongsToOptions<Columns extends
|
|
140
|
+
interface BelongsToOptions<Columns extends Column.Shape.QueryInit = Column.Shape.QueryInit, Related extends TableClass = TableClass> {
|
|
141
141
|
required?: boolean;
|
|
142
142
|
columns: (keyof Columns)[];
|
|
143
143
|
references: (keyof InstanceType<Related>['columns']['shape'])[];
|
|
144
144
|
foreignKey?: boolean | TableData.References.Options;
|
|
145
|
-
on?:
|
|
145
|
+
on?: ColumnsShape.InputPartial<InstanceType<Related>['columns']['shape']>;
|
|
146
146
|
}
|
|
147
147
|
type BelongsToFKey<Relation extends RelationThunkBase> = Relation['options'] extends RelationRefsOptions ? Relation['options']['columns'][number] : never;
|
|
148
148
|
type BelongsToParams<T extends RelationConfigSelf, Relation extends BelongsTo> = {
|
|
@@ -314,7 +314,7 @@ interface HasAndBelongsToMany extends RelationThunkBase {
|
|
|
314
314
|
type: 'hasAndBelongsToMany';
|
|
315
315
|
options: HasAndBelongsToManyOptions;
|
|
316
316
|
}
|
|
317
|
-
interface HasAndBelongsToManyOptions<Columns extends
|
|
317
|
+
interface HasAndBelongsToManyOptions<Columns extends Column.Shape.QueryInit = Column.Shape.QueryInit, Related extends TableClass = TableClass> {
|
|
318
318
|
required?: boolean;
|
|
319
319
|
columns: (keyof Columns)[];
|
|
320
320
|
references: string[];
|
|
@@ -325,7 +325,7 @@ interface HasAndBelongsToManyOptions<Columns extends ColumnsShapeBase = ColumnsS
|
|
|
325
325
|
references: (keyof InstanceType<Related>['columns']['shape'])[];
|
|
326
326
|
foreignKey?: boolean | TableData.References.Options;
|
|
327
327
|
};
|
|
328
|
-
on?:
|
|
328
|
+
on?: ColumnsShape.InputPartial<InstanceType<Related>['columns']['shape']>;
|
|
329
329
|
}
|
|
330
330
|
type HasAndBelongsToManyParams<T extends RelationConfigSelf, Relation extends HasAndBelongsToMany> = {
|
|
331
331
|
[Name in Relation['options']['columns'][number]]: T['columns']['shape'][Name]['type'];
|
|
@@ -425,7 +425,7 @@ interface RelationThunks {
|
|
|
425
425
|
type RelationTableToQuery<Relation extends RelationThunkBase> = ORMTableInputToQueryBuilder<InstanceType<ReturnType<Relation['fn']>>>;
|
|
426
426
|
interface RelationConfigSelf {
|
|
427
427
|
columns: {
|
|
428
|
-
shape:
|
|
428
|
+
shape: Column.Shape.QueryInit;
|
|
429
429
|
};
|
|
430
430
|
relations: RelationThunks;
|
|
431
431
|
}
|
|
@@ -455,7 +455,7 @@ type ORMTableInputToQueryBuilder<T extends ORMTableInput> = T extends RelationCo
|
|
|
455
455
|
interface ORMTableInput {
|
|
456
456
|
table: string;
|
|
457
457
|
columns: {
|
|
458
|
-
shape:
|
|
458
|
+
shape: Column.Shape.QueryInit;
|
|
459
459
|
data: MaybeArray<TableDataItem>;
|
|
460
460
|
};
|
|
461
461
|
schema?: string;
|
|
@@ -475,31 +475,31 @@ interface ORMTableInput {
|
|
|
475
475
|
type Queryable<T extends ORMTableInput> = ShallowSimplify<{
|
|
476
476
|
[K in keyof T['columns']['shape']]?: T['columns']['shape'][K]['queryType'];
|
|
477
477
|
}>;
|
|
478
|
-
type DefaultSelect<T extends ORMTableInput> = ShallowSimplify<
|
|
479
|
-
type Selectable<T extends ORMTableInput> = T['computed'] extends ((t: never) => infer R extends ComputedOptionsConfig) ? ShallowSimplify<
|
|
478
|
+
type DefaultSelect<T extends ORMTableInput> = ShallowSimplify<ColumnsShape.DefaultOutput<T['columns']['shape']>>;
|
|
479
|
+
type Selectable<T extends ORMTableInput> = T['computed'] extends ((t: never) => infer R extends ComputedOptionsConfig) ? ShallowSimplify<ColumnsShape.Output<T['columns']['shape']> & {
|
|
480
480
|
[K in keyof R]: R[K] extends QueryOrExpression<unknown> ? R[K]['result']['value']['outputType'] : R[K] extends () => {
|
|
481
481
|
result: {
|
|
482
|
-
value: infer Value extends QueryColumn;
|
|
482
|
+
value: infer Value extends Column.Pick.QueryColumn;
|
|
483
483
|
};
|
|
484
484
|
} ? Value['outputType'] : never;
|
|
485
|
-
}> : ShallowSimplify<
|
|
486
|
-
type Insertable<T extends ORMTableInput> = ShallowSimplify<
|
|
487
|
-
type Updatable<T extends ORMTableInput> = ShallowSimplify<
|
|
485
|
+
}> : ShallowSimplify<ColumnsShape.Output<T['columns']['shape']>>;
|
|
486
|
+
type Insertable<T extends ORMTableInput> = ShallowSimplify<ColumnsShape.Input<T['columns']['shape']>>;
|
|
487
|
+
type Updatable<T extends ORMTableInput> = ShallowSimplify<ColumnsShape.InputPartial<T['columns']['shape']>>;
|
|
488
488
|
type BeforeHookMethod = (cb: QueryBeforeHookInternal) => void;
|
|
489
489
|
type AfterHookMethod = (cb: QueryAfterHook) => void;
|
|
490
|
-
type AfterSelectableHookMethod = <Shape extends QueryColumns, S extends (keyof Shape)[]>(this: {
|
|
490
|
+
type AfterSelectableHookMethod = <Shape extends Column.QueryColumns, S extends (keyof Shape)[]>(this: {
|
|
491
491
|
columns: {
|
|
492
492
|
shape: Shape;
|
|
493
493
|
};
|
|
494
494
|
}, select: S, cb: AfterHook<S, Shape>) => void;
|
|
495
|
-
interface SetColumnsResult<Shape extends
|
|
495
|
+
interface SetColumnsResult<Shape extends Column.Shape.QueryInit, Data extends MaybeArray<MaybeArray<TableDataItem>>> {
|
|
496
496
|
shape: Shape;
|
|
497
497
|
data: Data extends unknown[] ? Data : [Data];
|
|
498
498
|
}
|
|
499
499
|
interface BaseTableInstance<ColumnTypes> {
|
|
500
500
|
table: string;
|
|
501
501
|
columns: {
|
|
502
|
-
shape:
|
|
502
|
+
shape: Column.Shape.QueryInit;
|
|
503
503
|
data: MaybeArray<TableDataItem>;
|
|
504
504
|
};
|
|
505
505
|
schema?: string;
|
|
@@ -509,10 +509,10 @@ interface BaseTableInstance<ColumnTypes> {
|
|
|
509
509
|
q: QueryData;
|
|
510
510
|
language?: string;
|
|
511
511
|
filePath: string;
|
|
512
|
-
result:
|
|
512
|
+
result: Column.Shape.QueryInit;
|
|
513
513
|
clone<T extends IsQuery>(this: T): T;
|
|
514
514
|
getFilePath(): string;
|
|
515
|
-
setColumns<Shape extends
|
|
515
|
+
setColumns<Shape extends Column.Shape.QueryInit, Data extends MaybeArray<TableDataItem>>(fn: (t: ColumnTypes) => Shape, tableData?: TableDataFn<Shape, Data>): SetColumnsResult<Shape, Data>;
|
|
516
516
|
/**
|
|
517
517
|
* You can add a generated column in the migration (see [generated](/guide/migration-column-methods.html#generated-column)),
|
|
518
518
|
* such column will persist in the database, it can be indexed.
|
|
@@ -603,7 +603,7 @@ interface BaseTableInstance<ColumnTypes> {
|
|
|
603
603
|
*
|
|
604
604
|
* @param computed - object where keys are column names and values are functions returning raw SQL
|
|
605
605
|
*/
|
|
606
|
-
setComputed<Shape extends
|
|
606
|
+
setComputed<Shape extends Column.Shape.QueryInit, Computed extends ComputedOptionsFactory<ColumnTypes, Shape>>(this: {
|
|
607
607
|
columns: {
|
|
608
608
|
shape: Shape;
|
|
609
609
|
};
|
|
@@ -611,13 +611,13 @@ interface BaseTableInstance<ColumnTypes> {
|
|
|
611
611
|
/**
|
|
612
612
|
* See {@link ScopeMethods}
|
|
613
613
|
*/
|
|
614
|
-
setScopes<Table extends string, Shape extends
|
|
614
|
+
setScopes<Table extends string, Shape extends Column.Shape.QueryInit, Keys extends string>(this: {
|
|
615
615
|
table: Table;
|
|
616
616
|
columns: {
|
|
617
617
|
shape: Shape;
|
|
618
618
|
};
|
|
619
619
|
}, scopes: DbTableOptionScopes<Table, Shape, Keys>): CoreQueryScopes<Keys>;
|
|
620
|
-
belongsTo<Columns extends
|
|
620
|
+
belongsTo<Columns extends Column.Shape.QueryInit, Related extends TableClass, Options extends BelongsToOptions<Columns, Related>>(this: {
|
|
621
621
|
columns: {
|
|
622
622
|
shape: Columns;
|
|
623
623
|
};
|
|
@@ -626,7 +626,7 @@ interface BaseTableInstance<ColumnTypes> {
|
|
|
626
626
|
fn: () => Related;
|
|
627
627
|
options: Options;
|
|
628
628
|
};
|
|
629
|
-
hasOne<Columns extends
|
|
629
|
+
hasOne<Columns extends Column.Shape.QueryInit, Related extends TableClass, Through extends string, Source extends string, Options extends HasOneOptions<Columns, Related, Through, Source>>(this: {
|
|
630
630
|
columns: {
|
|
631
631
|
shape: Columns;
|
|
632
632
|
};
|
|
@@ -635,7 +635,7 @@ interface BaseTableInstance<ColumnTypes> {
|
|
|
635
635
|
fn: () => Related;
|
|
636
636
|
options: Options;
|
|
637
637
|
};
|
|
638
|
-
hasMany<Columns extends
|
|
638
|
+
hasMany<Columns extends Column.Shape.QueryInit, Related extends TableClass, Through extends string, Source extends string, Options extends HasOneOptions<Columns, Related, Through, Source>>(this: {
|
|
639
639
|
columns: {
|
|
640
640
|
shape: Columns;
|
|
641
641
|
};
|
|
@@ -644,7 +644,7 @@ interface BaseTableInstance<ColumnTypes> {
|
|
|
644
644
|
fn: () => Related;
|
|
645
645
|
options: Options;
|
|
646
646
|
};
|
|
647
|
-
hasAndBelongsToMany<Columns extends
|
|
647
|
+
hasAndBelongsToMany<Columns extends Column.Shape.QueryInit, Related extends TableClass, Options extends HasAndBelongsToManyOptions<Columns, Related>>(this: {
|
|
648
648
|
columns: {
|
|
649
649
|
shape: Columns;
|
|
650
650
|
};
|
|
@@ -673,8 +673,8 @@ interface BaseTableClass<SchemaConfig extends ColumnSchemaConfig, ColumnTypes> {
|
|
|
673
673
|
exportAs: string;
|
|
674
674
|
columnTypes: ColumnTypes;
|
|
675
675
|
getFilePath(): string;
|
|
676
|
-
sql<T>(...args: StaticSQLArgs): RawSQL<
|
|
677
|
-
sql<T>(...args: [DynamicSQLArg<
|
|
676
|
+
sql<T>(...args: StaticSQLArgs): RawSQL<Column.Pick.QueryColumnOfType<T>, ColumnTypes>;
|
|
677
|
+
sql<T>(...args: [DynamicSQLArg<Column.Pick.QueryColumnOfType<T>>]): DynamicRawSQL<Column.Pick.QueryColumnOfType<T>, ColumnTypes>;
|
|
678
678
|
new (): BaseTableInstance<ColumnTypes>;
|
|
679
679
|
instance(): BaseTableInstance<ColumnTypes>;
|
|
680
680
|
/**
|
package/dist/index.js
CHANGED
|
@@ -402,45 +402,48 @@ class BelongsToVirtualColumn extends pqb.VirtualColumn {
|
|
|
402
402
|
super(schema);
|
|
403
403
|
this.key = key;
|
|
404
404
|
this.state = state;
|
|
405
|
-
this.nestedInsert = nestedInsert$3(this.state);
|
|
406
405
|
this.nestedUpdate = nestedUpdate$3(this.state);
|
|
407
406
|
}
|
|
408
|
-
create(q, ctx, item
|
|
407
|
+
create(q, ctx, item) {
|
|
409
408
|
const {
|
|
410
409
|
key,
|
|
411
|
-
state: { primaryKeys, foreignKeys }
|
|
410
|
+
state: { query, primaryKeys, foreignKeys }
|
|
412
411
|
} = this;
|
|
413
|
-
const
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
ctx.columns.set(key2, index = ctx.columns.size);
|
|
412
|
+
for (const key2 of foreignKeys) {
|
|
413
|
+
if (!ctx.columns.has(key2)) {
|
|
414
|
+
ctx.columns.set(key2, ctx.columns.size);
|
|
417
415
|
}
|
|
418
|
-
return index;
|
|
419
|
-
});
|
|
420
|
-
const store = ctx;
|
|
421
|
-
if (!store.belongsTo) store.belongsTo = {};
|
|
422
|
-
const values = [rowIndex, columnIndexes, item[key]];
|
|
423
|
-
if (store.belongsTo[key]) {
|
|
424
|
-
store.belongsTo[key].push(values);
|
|
425
|
-
return;
|
|
426
416
|
}
|
|
427
|
-
const
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
417
|
+
const value = item[key];
|
|
418
|
+
if ("create" in value || "connectOrCreate" in value) {
|
|
419
|
+
foreignKeys.forEach((foreignKey) => item[foreignKey] = new pqb.RawSQL(""));
|
|
420
|
+
const selectPKeys = query.select(...primaryKeys);
|
|
421
|
+
pqb._with(
|
|
422
|
+
q,
|
|
423
|
+
(as) => {
|
|
424
|
+
foreignKeys.forEach((foreignKey, i) => {
|
|
425
|
+
item[foreignKey]._sql = `(SELECT "${as}"."${primaryKeys[i]}" FROM "${as}")`;
|
|
426
|
+
});
|
|
427
|
+
},
|
|
428
|
+
"create" in value ? pqb._queryCreate(selectPKeys, value.create) : pqb._orCreate(
|
|
429
|
+
pqb._queryWhere(selectPKeys, [
|
|
430
|
+
value.connectOrCreate.where
|
|
431
|
+
]),
|
|
432
|
+
value.connectOrCreate.create
|
|
433
|
+
)
|
|
434
434
|
);
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
435
|
+
return;
|
|
436
|
+
} else if ("connect" in value) {
|
|
437
|
+
const as = pqb.getFreeAlias(q.q.withShapes, "q");
|
|
438
|
+
pqb._with(q, as, query.select(...primaryKeys).findBy(value.connect));
|
|
439
|
+
foreignKeys.map((foreignKey, i) => {
|
|
440
|
+
const selectColumn = `(SELECT "${as}"."${primaryKeys[i]}" FROM "${as}")`;
|
|
441
|
+
item[foreignKey] = new pqb.RawSQL(
|
|
442
|
+
i === 0 ? `CASE WHEN (SELECT count(*) FROM "${as}") = 0 AND (SELECT 'not-found')::int = 0 THEN NULL ELSE ${selectColumn} END` : selectColumn
|
|
443
|
+
);
|
|
444
|
+
});
|
|
445
|
+
return;
|
|
446
|
+
}
|
|
444
447
|
}
|
|
445
448
|
update(q, ctx, set) {
|
|
446
449
|
q.q.wrapInTransaction = true;
|
|
@@ -516,80 +519,6 @@ const makeBelongsToMethod = (tableConfig, table, relation, relationName, query)
|
|
|
516
519
|
reverseJoin
|
|
517
520
|
};
|
|
518
521
|
};
|
|
519
|
-
const nestedInsert$3 = ({ query, primaryKeys, on }) => {
|
|
520
|
-
return async (_, data) => {
|
|
521
|
-
const t = query.clone();
|
|
522
|
-
const items = [];
|
|
523
|
-
for (const item of data) {
|
|
524
|
-
if (item.connectOrCreate) {
|
|
525
|
-
items.push(
|
|
526
|
-
on ? {
|
|
527
|
-
...item,
|
|
528
|
-
connectOrCreate: {
|
|
529
|
-
...item.connectOrCreate,
|
|
530
|
-
where: { ...item.connectOrCreate.where, ...on }
|
|
531
|
-
}
|
|
532
|
-
} : item
|
|
533
|
-
);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
let connectOrCreated;
|
|
537
|
-
if (items.length) {
|
|
538
|
-
for (let i = 0, len = items.length; i < len; i++) {
|
|
539
|
-
items[i] = t.findByOptional(
|
|
540
|
-
items[i].connectOrCreate.where
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
connectOrCreated = await Promise.all(items);
|
|
544
|
-
} else {
|
|
545
|
-
connectOrCreated = pqb.emptyArray;
|
|
546
|
-
}
|
|
547
|
-
let connectOrCreatedI = 0;
|
|
548
|
-
items.length = 0;
|
|
549
|
-
for (const item of data) {
|
|
550
|
-
if (item.connectOrCreate) {
|
|
551
|
-
if (!connectOrCreated[connectOrCreatedI++]) items.push(item);
|
|
552
|
-
} else if (item.create) {
|
|
553
|
-
items.push(item);
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
let created;
|
|
557
|
-
if (items.length) {
|
|
558
|
-
for (let i = 0, len = items.length; i < len; i++) {
|
|
559
|
-
items[i] = "create" in items[i] ? items[i].create : items[i].connectOrCreate.create;
|
|
560
|
-
}
|
|
561
|
-
created = await pqb._queryCreateMany(
|
|
562
|
-
t.select(...primaryKeys),
|
|
563
|
-
items
|
|
564
|
-
);
|
|
565
|
-
} else {
|
|
566
|
-
created = pqb.emptyArray;
|
|
567
|
-
}
|
|
568
|
-
items.length = 0;
|
|
569
|
-
for (const item of data) {
|
|
570
|
-
if (item.connect) {
|
|
571
|
-
items.push(
|
|
572
|
-
on ? { ...item, connect: { ...item.connect, ...on } } : item
|
|
573
|
-
);
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
let connected;
|
|
577
|
-
if (items.length) {
|
|
578
|
-
for (let i = 0, len = items.length; i < len; i++) {
|
|
579
|
-
items[i] = t.findBy(items[i].connect);
|
|
580
|
-
}
|
|
581
|
-
connected = await Promise.all(items);
|
|
582
|
-
} else {
|
|
583
|
-
connected = pqb.emptyArray;
|
|
584
|
-
}
|
|
585
|
-
let createdI = 0;
|
|
586
|
-
let connectedI = 0;
|
|
587
|
-
connectOrCreatedI = 0;
|
|
588
|
-
return data.map((item) => {
|
|
589
|
-
return item.connectOrCreate ? connectOrCreated[connectOrCreatedI++] || created[createdI++] : item.connect ? connected[connectedI++] : created[createdI++];
|
|
590
|
-
});
|
|
591
|
-
};
|
|
592
|
-
};
|
|
593
522
|
const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
594
523
|
return (q, update, params, state) => {
|
|
595
524
|
if (params.upsert && pqb.isQueryReturnsAll(q)) {
|
|
@@ -857,7 +786,7 @@ const makeHasOneMethod = (tableConfig, table, relation, relationName, query) =>
|
|
|
857
786
|
const baseQuery = query2.clone();
|
|
858
787
|
baseQuery.q.select = fromQuerySelect;
|
|
859
788
|
const q = relationQuery.q;
|
|
860
|
-
q.insertFrom = baseQuery;
|
|
789
|
+
q.insertFrom = pqb.prepareSubQueryForSql(q, baseQuery);
|
|
861
790
|
q.values = [];
|
|
862
791
|
};
|
|
863
792
|
}
|
|
@@ -1135,7 +1064,7 @@ const makeHasManyMethod = (tableConfig, table, relation, relationName, query) =>
|
|
|
1135
1064
|
const baseQuery = query2.clone();
|
|
1136
1065
|
baseQuery.q.select = fromQuerySelect;
|
|
1137
1066
|
const q = relationQuery.q;
|
|
1138
|
-
q.insertFrom = baseQuery;
|
|
1067
|
+
q.insertFrom = pqb.prepareSubQueryForSql(q, baseQuery);
|
|
1139
1068
|
q.values = [];
|
|
1140
1069
|
};
|
|
1141
1070
|
}
|
|
@@ -1407,7 +1336,9 @@ const makeHasAndBelongsToManyMethod = (tableConfig, table, qb, relation, relatio
|
|
|
1407
1336
|
const primaryKeysShape = {};
|
|
1408
1337
|
for (let i = 0; i < len; i++) {
|
|
1409
1338
|
const pk = primaryKeys[i];
|
|
1410
|
-
shape[foreignKeys[i]] = removeColumnName(
|
|
1339
|
+
shape[foreignKeys[i]] = removeColumnName(
|
|
1340
|
+
table.shape[pk]
|
|
1341
|
+
);
|
|
1411
1342
|
primaryKeysShape[pk] = table.shape[pk];
|
|
1412
1343
|
}
|
|
1413
1344
|
for (let i = 0; i < throughLen; i++) {
|