orchid-orm 1.17.37 → 1.18.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 +7 -7
- package/dist/index.js +156 -118
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +151 -99
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Query, QueryWithTable, SetQueryTableAlias, WhereArg, UpdateData, CreateData, AddQueryDefaults, Db, IsolationLevel, TransactionOptions, Adapter, FromArgs, FromResult, AdapterOptions, QueryLogOptions, NoPrimaryKeyOption, RelationQuery, RelationConfigBase, RelationQueryBase, ComputedColumnsBase, QueryData, QueryBase, DefaultColumnTypes, QueryBeforeHook, QueryAfterHook, AfterHook, WhereResult, MergeQuery, SetQueryReturns, QueryReturnType } from 'pqb';
|
|
2
|
-
export
|
|
1
|
+
import { Query, QueryWithTable, SetQueryTableAlias, RelationJoinQuery, WhereArg, UpdateData, CreateData, AddQueryDefaults, Db, IsolationLevel, TransactionOptions, Adapter, FromArgs, FromResult, AdapterOptions, QueryLogOptions, NoPrimaryKeyOption, RelationQuery, RelationConfigBase, RelationQueryBase, ComputedColumnsBase, QueryData, QueryBase, DefaultColumnTypes, QueryBeforeHook, QueryAfterHook, AfterHook, WhereResult, MergeQuery, SetQueryReturns, QueryReturnType } from 'pqb';
|
|
2
|
+
export * from 'pqb';
|
|
3
3
|
import { EmptyObject, MaybeArray, StringKey, ColumnsShapeBase, ColumnShapeQueryType, ColumnShapeOutput, ColumnShapeInput } from 'orchid-core';
|
|
4
4
|
|
|
5
5
|
type RelationCommonOptions<Related extends TableClass = TableClass, Scope extends Query = Query> = {
|
|
@@ -32,7 +32,7 @@ type BelongsToInfo<T extends Table, Relation extends BelongsTo, K extends string
|
|
|
32
32
|
}>, Required = Relation['options']['required'] extends true ? true : false> = {
|
|
33
33
|
table: Q;
|
|
34
34
|
query: Q;
|
|
35
|
-
joinQuery
|
|
35
|
+
joinQuery: RelationJoinQuery;
|
|
36
36
|
one: true;
|
|
37
37
|
required: Required;
|
|
38
38
|
omitForeignKeyInCreate: FK;
|
|
@@ -80,7 +80,7 @@ type HasManyOptions<Self extends Table = Table, Related extends TableClass = Tab
|
|
|
80
80
|
type HasManyInfo<T extends Table, Relations extends RelationThunks, Relation extends HasMany, K extends string, Populate extends Record<string, true> = Relation['options'] extends RelationRefsOptions ? Record<Relation['options']['references'][number], true> : Relation['options'] extends RelationKeysOptions ? Record<Relation['options']['foreignKey'], true> : never, TC extends TableClass = ReturnType<Relation['fn']>, Q extends QueryWithTable = SetQueryTableAlias<DbTable<TC>, K>, NestedCreateQuery extends Query = Relation['options'] extends RelationThroughOptions ? Q : AddQueryDefaults<Q, Populate>> = {
|
|
81
81
|
table: Q;
|
|
82
82
|
query: Q;
|
|
83
|
-
joinQuery
|
|
83
|
+
joinQuery: RelationJoinQuery;
|
|
84
84
|
one: false;
|
|
85
85
|
required: Relation['options']['required'] extends true ? true : false;
|
|
86
86
|
omitForeignKeyInCreate: never;
|
|
@@ -118,7 +118,7 @@ type HasOneOptions<Self extends Table = Table, Related extends TableClass = Tabl
|
|
|
118
118
|
type HasOneInfo<T extends Table, Relations extends RelationThunks, Relation extends HasOne, K extends string, Populate extends Record<string, true> = Relation['options'] extends RelationRefsOptions ? Record<Relation['options']['references'][number], true> : Relation['options'] extends RelationKeysOptions ? Record<Relation['options']['foreignKey'], true> : never, TC extends TableClass = ReturnType<Relation['fn']>, Q extends QueryWithTable = SetQueryTableAlias<DbTable<TC>, K>, NestedCreateQuery extends Query = Relation['options'] extends RelationThroughOptions ? Q : AddQueryDefaults<Q, Populate>> = {
|
|
119
119
|
table: Q;
|
|
120
120
|
query: Q;
|
|
121
|
-
joinQuery
|
|
121
|
+
joinQuery: RelationJoinQuery;
|
|
122
122
|
one: true;
|
|
123
123
|
required: Relation['options']['required'] extends true ? true : false;
|
|
124
124
|
omitForeignKeyInCreate: never;
|
|
@@ -257,7 +257,7 @@ type HasAndBelongsToManyOptions<Self extends Table = Table, Related extends Tabl
|
|
|
257
257
|
type HasAndBelongsToManyInfo<T extends Table, Relation extends HasAndBelongsToMany, K extends string, TC extends TableClass = ReturnType<Relation['fn']>, Q extends QueryWithTable = SetQueryTableAlias<DbTable<TC>, K>> = {
|
|
258
258
|
table: Q;
|
|
259
259
|
query: Q;
|
|
260
|
-
joinQuery
|
|
260
|
+
joinQuery: RelationJoinQuery;
|
|
261
261
|
one: false;
|
|
262
262
|
required: Relation['options']['required'] extends true ? true : false;
|
|
263
263
|
omitForeignKeyInCreate: never;
|
|
@@ -550,4 +550,4 @@ type Repo<T extends Query, Methods extends MethodsBase<T>, Mapped = MapMethods<T
|
|
|
550
550
|
}>(q: Q) => Q & Mapped) & T & Mapped;
|
|
551
551
|
declare const createRepo: <T extends Query, Methods extends MethodsBase<T>>(table: T, methods: Methods) => Repo<T, Methods, MapMethods<T, Methods>>;
|
|
552
552
|
|
|
553
|
-
export { BaseTableClass, BaseTableInstance, DbTable, Insertable, MapMethods, MapQueryMethods, MethodsBase, OrchidORM,
|
|
553
|
+
export { BaseTableClass, BaseTableInstance, DbTable, Insertable, MapMethods, MapQueryMethods, MethodsBase, OrchidORM, Queryable, Repo, ScopeFn, Selectable, Table, TableClass, TableClasses, TableToDb, Updateable, createBaseTable, createRepo, orchidORM };
|
package/dist/index.js
CHANGED
|
@@ -182,31 +182,45 @@ const relationWhere = (len, keys, valueKeys) => (params) => {
|
|
|
182
182
|
}
|
|
183
183
|
return obj;
|
|
184
184
|
};
|
|
185
|
-
function joinHasThrough(q,
|
|
185
|
+
function joinHasThrough(q, baseQuery, joiningQuery, throughRelation, sourceRelation) {
|
|
186
186
|
return q.whereExists(
|
|
187
|
-
throughRelation.joinQuery(
|
|
187
|
+
throughRelation.joinQuery(throughRelation.query, baseQuery),
|
|
188
188
|
() => {
|
|
189
|
-
const as = pqb.getQueryAs(
|
|
189
|
+
const as = pqb.getQueryAs(joiningQuery);
|
|
190
190
|
return sourceRelation.joinQuery(
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
sourceRelation.query.as(as),
|
|
192
|
+
throughRelation.query
|
|
193
193
|
);
|
|
194
194
|
}
|
|
195
195
|
);
|
|
196
196
|
}
|
|
197
|
-
function joinHasRelation(
|
|
198
|
-
const q =
|
|
197
|
+
function joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len) {
|
|
198
|
+
const q = joiningQuery.clone();
|
|
199
199
|
pqb.setQueryObjectValue(
|
|
200
200
|
q,
|
|
201
201
|
"joinedShapes",
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
baseQuery.q.as || baseQuery.table,
|
|
203
|
+
baseQuery.q.shape
|
|
204
204
|
);
|
|
205
205
|
for (let i = 0; i < len; i++) {
|
|
206
|
-
pqb.pushQueryOn(q,
|
|
206
|
+
pqb.pushQueryOn(q, baseQuery, joiningQuery, foreignKeys[i], primaryKeys[i]);
|
|
207
207
|
}
|
|
208
208
|
return q;
|
|
209
209
|
}
|
|
210
|
+
const joinQueryChainingHOF = (reverseJoin, joinQuery) => (joiningQuery, baseQuery) => {
|
|
211
|
+
const chain = joiningQuery.q.relChain;
|
|
212
|
+
if (!chain || chain.length === 1) {
|
|
213
|
+
return joinQuery(joiningQuery, baseQuery);
|
|
214
|
+
}
|
|
215
|
+
const last = chain[chain.length - 1];
|
|
216
|
+
const query = "relationConfig" in last ? last.relationConfig.joinQuery(last, baseQuery) : last;
|
|
217
|
+
const inner = reverseJoin(query, joiningQuery);
|
|
218
|
+
return joiningQuery.where({
|
|
219
|
+
EXISTS: {
|
|
220
|
+
args: [inner]
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
};
|
|
210
224
|
|
|
211
225
|
class BelongsToVirtualColumn extends pqb.VirtualColumn {
|
|
212
226
|
constructor(key, state) {
|
|
@@ -266,31 +280,33 @@ const makeBelongsToMethod = (relation, relationName, query) => {
|
|
|
266
280
|
const len = primaryKeys.length;
|
|
267
281
|
const state = { query, primaryKeys, foreignKeys, len };
|
|
268
282
|
const makeWhere = relationWhere(len, primaryKeys, foreignKeys);
|
|
269
|
-
const join = (
|
|
270
|
-
const q =
|
|
283
|
+
const join = (baseQuery, joiningQuery, primaryKeys2, foreignKeys2) => {
|
|
284
|
+
const q = joiningQuery.clone();
|
|
271
285
|
pqb.setQueryObjectValue(
|
|
272
286
|
q,
|
|
273
287
|
"joinedShapes",
|
|
274
|
-
|
|
275
|
-
|
|
288
|
+
baseQuery.q.as || baseQuery.table,
|
|
289
|
+
baseQuery.q.shape
|
|
276
290
|
);
|
|
277
291
|
for (let i = 0; i < len; i++) {
|
|
278
|
-
pqb.pushQueryOn(q,
|
|
292
|
+
pqb.pushQueryOn(q, baseQuery, joiningQuery, primaryKeys2[i], foreignKeys2[i]);
|
|
279
293
|
}
|
|
280
294
|
return q;
|
|
281
295
|
};
|
|
296
|
+
const reverseJoin = (baseQuery, joiningQuery) => {
|
|
297
|
+
return join(joiningQuery, baseQuery, foreignKeys, primaryKeys);
|
|
298
|
+
};
|
|
282
299
|
return {
|
|
283
300
|
returns: "one",
|
|
284
301
|
method(params) {
|
|
285
302
|
return query.where(makeWhere(params));
|
|
286
303
|
},
|
|
287
304
|
virtualColumn: new BelongsToVirtualColumn(relationName, state),
|
|
288
|
-
joinQuery(
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
305
|
+
joinQuery: joinQueryChainingHOF(
|
|
306
|
+
reverseJoin,
|
|
307
|
+
(joiningQuery, baseQuery) => join(baseQuery, joiningQuery, primaryKeys, foreignKeys)
|
|
308
|
+
),
|
|
309
|
+
reverseJoin
|
|
294
310
|
};
|
|
295
311
|
};
|
|
296
312
|
const nestedInsert$3 = ({ query, primaryKeys }) => {
|
|
@@ -524,8 +540,17 @@ const makeHasOneMethod = (table, relation, relationName, query) => {
|
|
|
524
540
|
const { through, source } = relation.options;
|
|
525
541
|
const throughRelation = getThroughRelation(table, through);
|
|
526
542
|
const sourceRelation = getSourceRelation(throughRelation, source);
|
|
527
|
-
const sourceQuery = sourceRelation.joinQuery(
|
|
543
|
+
const sourceQuery = sourceRelation.joinQuery(sourceRelation.query, throughRelation.query).as(relationName);
|
|
528
544
|
const whereExistsCallback = () => sourceQuery;
|
|
545
|
+
const reverseJoin2 = (baseQuery, joiningQuery) => {
|
|
546
|
+
return joinHasThrough(
|
|
547
|
+
baseQuery,
|
|
548
|
+
baseQuery,
|
|
549
|
+
joiningQuery,
|
|
550
|
+
throughRelation,
|
|
551
|
+
sourceRelation
|
|
552
|
+
);
|
|
553
|
+
};
|
|
529
554
|
return {
|
|
530
555
|
returns: "one",
|
|
531
556
|
method: (params) => {
|
|
@@ -535,24 +560,17 @@ const makeHasOneMethod = (table, relation, relationName, query) => {
|
|
|
535
560
|
whereExistsCallback
|
|
536
561
|
);
|
|
537
562
|
},
|
|
538
|
-
joinQuery(
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
sourceRelation
|
|
545
|
-
);
|
|
546
|
-
},
|
|
547
|
-
reverseJoin(fromQuery, toQuery) {
|
|
548
|
-
return joinHasThrough(
|
|
549
|
-
fromQuery,
|
|
550
|
-
fromQuery,
|
|
551
|
-
toQuery,
|
|
563
|
+
joinQuery: joinQueryChainingHOF(
|
|
564
|
+
reverseJoin2,
|
|
565
|
+
(joiningQuery, baseQuery) => joinHasThrough(
|
|
566
|
+
joiningQuery,
|
|
567
|
+
baseQuery,
|
|
568
|
+
joiningQuery,
|
|
552
569
|
throughRelation,
|
|
553
570
|
sourceRelation
|
|
554
|
-
)
|
|
555
|
-
|
|
571
|
+
)
|
|
572
|
+
),
|
|
573
|
+
reverseJoin: reverseJoin2
|
|
556
574
|
};
|
|
557
575
|
}
|
|
558
576
|
const primaryKeys = "columns" in relation.options ? relation.options.columns : [relation.options.primaryKey];
|
|
@@ -564,6 +582,15 @@ const makeHasOneMethod = (table, relation, relationName, query) => {
|
|
|
564
582
|
reversedOn[foreignKeys[i]] = primaryKeys[i];
|
|
565
583
|
}
|
|
566
584
|
const fromQuerySelect = [{ selectAs: reversedOn }];
|
|
585
|
+
const reverseJoin = (baseQuery, joiningQuery) => {
|
|
586
|
+
return joinHasRelation(
|
|
587
|
+
joiningQuery,
|
|
588
|
+
baseQuery,
|
|
589
|
+
foreignKeys,
|
|
590
|
+
primaryKeys,
|
|
591
|
+
len
|
|
592
|
+
);
|
|
593
|
+
};
|
|
567
594
|
return {
|
|
568
595
|
returns: "one",
|
|
569
596
|
method: (params) => {
|
|
@@ -574,19 +601,18 @@ const makeHasOneMethod = (table, relation, relationName, query) => {
|
|
|
574
601
|
return query.where(values)._defaults(values);
|
|
575
602
|
},
|
|
576
603
|
virtualColumn: new HasOneVirtualColumn(relationName, state),
|
|
577
|
-
joinQuery(
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
},
|
|
604
|
+
joinQuery: joinQueryChainingHOF(
|
|
605
|
+
reverseJoin,
|
|
606
|
+
(joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)
|
|
607
|
+
),
|
|
608
|
+
reverseJoin,
|
|
583
609
|
modifyRelatedQuery(relationQuery) {
|
|
584
610
|
return (query2) => {
|
|
585
|
-
const
|
|
586
|
-
|
|
611
|
+
const baseQuery = query2.clone();
|
|
612
|
+
baseQuery.q.select = fromQuerySelect;
|
|
587
613
|
const q = relationQuery.q;
|
|
588
614
|
q.kind = "from";
|
|
589
|
-
q.values = { from:
|
|
615
|
+
q.values = { from: baseQuery };
|
|
590
616
|
};
|
|
591
617
|
}
|
|
592
618
|
};
|
|
@@ -760,10 +786,19 @@ const makeHasManyMethod = (table, relation, relationName, query) => {
|
|
|
760
786
|
const sourceRelation = getSourceRelation(throughRelation, source);
|
|
761
787
|
const sourceRelationQuery = sourceRelation.query.as(relationName);
|
|
762
788
|
const sourceQuery = sourceRelation.joinQuery(
|
|
763
|
-
|
|
764
|
-
|
|
789
|
+
sourceRelationQuery,
|
|
790
|
+
throughRelation.query
|
|
765
791
|
);
|
|
766
792
|
const whereExistsCallback = () => sourceQuery;
|
|
793
|
+
const reverseJoin2 = (baseQuery, joiningQuery) => {
|
|
794
|
+
return joinHasThrough(
|
|
795
|
+
baseQuery,
|
|
796
|
+
baseQuery,
|
|
797
|
+
joiningQuery,
|
|
798
|
+
throughRelation,
|
|
799
|
+
sourceRelation
|
|
800
|
+
);
|
|
801
|
+
};
|
|
767
802
|
return {
|
|
768
803
|
returns: "many",
|
|
769
804
|
method: (params) => {
|
|
@@ -773,24 +808,17 @@ const makeHasManyMethod = (table, relation, relationName, query) => {
|
|
|
773
808
|
whereExistsCallback
|
|
774
809
|
);
|
|
775
810
|
},
|
|
776
|
-
joinQuery(
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
811
|
+
joinQuery: joinQueryChainingHOF(
|
|
812
|
+
reverseJoin2,
|
|
813
|
+
(joiningQuery, baseQuery) => joinHasThrough(
|
|
814
|
+
joiningQuery,
|
|
815
|
+
baseQuery,
|
|
816
|
+
joiningQuery,
|
|
781
817
|
throughRelation,
|
|
782
818
|
sourceRelation
|
|
783
|
-
)
|
|
784
|
-
|
|
785
|
-
reverseJoin
|
|
786
|
-
return joinHasThrough(
|
|
787
|
-
fromQuery,
|
|
788
|
-
fromQuery,
|
|
789
|
-
toQuery,
|
|
790
|
-
throughRelation,
|
|
791
|
-
sourceRelation
|
|
792
|
-
);
|
|
793
|
-
}
|
|
819
|
+
)
|
|
820
|
+
),
|
|
821
|
+
reverseJoin: reverseJoin2
|
|
794
822
|
};
|
|
795
823
|
}
|
|
796
824
|
const primaryKeys = "columns" in relation.options ? relation.options.columns : [relation.options.primaryKey];
|
|
@@ -802,6 +830,15 @@ const makeHasManyMethod = (table, relation, relationName, query) => {
|
|
|
802
830
|
reversedOn[foreignKeys[i]] = primaryKeys[i];
|
|
803
831
|
}
|
|
804
832
|
const fromQuerySelect = [{ selectAs: reversedOn }];
|
|
833
|
+
const reverseJoin = (baseQuery, joiningQuery) => {
|
|
834
|
+
return joinHasRelation(
|
|
835
|
+
joiningQuery,
|
|
836
|
+
baseQuery,
|
|
837
|
+
foreignKeys,
|
|
838
|
+
primaryKeys,
|
|
839
|
+
len
|
|
840
|
+
);
|
|
841
|
+
};
|
|
805
842
|
return {
|
|
806
843
|
returns: "many",
|
|
807
844
|
method: (params) => {
|
|
@@ -812,19 +849,18 @@ const makeHasManyMethod = (table, relation, relationName, query) => {
|
|
|
812
849
|
return query.where(values)._defaults(values);
|
|
813
850
|
},
|
|
814
851
|
virtualColumn: new HasManyVirtualColumn(relationName, state),
|
|
815
|
-
joinQuery(
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
},
|
|
852
|
+
joinQuery: joinQueryChainingHOF(
|
|
853
|
+
reverseJoin,
|
|
854
|
+
(joiningQuery, baseQuery) => joinHasRelation(baseQuery, joiningQuery, primaryKeys, foreignKeys, len)
|
|
855
|
+
),
|
|
856
|
+
reverseJoin,
|
|
821
857
|
modifyRelatedQuery(relationQuery) {
|
|
822
858
|
return (query2) => {
|
|
823
|
-
const
|
|
824
|
-
|
|
859
|
+
const baseQuery = query2.clone();
|
|
860
|
+
baseQuery.q.select = fromQuerySelect;
|
|
825
861
|
const q = relationQuery.q;
|
|
826
862
|
q.kind = "from";
|
|
827
|
-
q.values = { from:
|
|
863
|
+
q.values = { from: baseQuery };
|
|
828
864
|
};
|
|
829
865
|
}
|
|
830
866
|
};
|
|
@@ -1096,8 +1132,8 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1096
1132
|
throughForeignKeysFull,
|
|
1097
1133
|
throughPrimaryKeysFull
|
|
1098
1134
|
};
|
|
1099
|
-
const joinQuery = (
|
|
1100
|
-
return
|
|
1135
|
+
const joinQuery = (joiningQuery, tableAs, foreignAs) => {
|
|
1136
|
+
return joiningQuery.whereExists(subQuery, (q) => {
|
|
1101
1137
|
for (let i = 0; i < throughLen; i++) {
|
|
1102
1138
|
q._on(
|
|
1103
1139
|
throughForeignKeysFull[i],
|
|
@@ -1115,6 +1151,13 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1115
1151
|
obj[foreignKeys[i]] = primaryKeys[i];
|
|
1116
1152
|
}
|
|
1117
1153
|
const selectPrimaryKeysAsForeignKeys = [{ selectAs: obj }];
|
|
1154
|
+
const reverseJoin = (baseQuery2, joiningQuery) => {
|
|
1155
|
+
return joinQuery(
|
|
1156
|
+
baseQuery2,
|
|
1157
|
+
pqb.getQueryAs(baseQuery2),
|
|
1158
|
+
pqb.getQueryAs(joiningQuery)
|
|
1159
|
+
);
|
|
1160
|
+
};
|
|
1118
1161
|
return {
|
|
1119
1162
|
returns: "many",
|
|
1120
1163
|
method(params) {
|
|
@@ -1131,22 +1174,18 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1131
1174
|
});
|
|
1132
1175
|
},
|
|
1133
1176
|
virtualColumn: new HasAndBelongsToManyVirtualColumn(relationName, state),
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
pqb.getQueryAs(fromQuery),
|
|
1140
|
-
pqb.getQueryAs(toQuery)
|
|
1177
|
+
joinQuery: joinQueryChainingHOF(reverseJoin, (joiningQuery, baseQuery2) => {
|
|
1178
|
+
const joined = joinQuery(
|
|
1179
|
+
joiningQuery,
|
|
1180
|
+
pqb.getQueryAs(baseQuery2),
|
|
1181
|
+
pqb.getQueryAs(joiningQuery)
|
|
1141
1182
|
);
|
|
1142
|
-
|
|
1143
|
-
[
|
|
1183
|
+
joined.q.joinedShapes = __spreadProps$1(__spreadValues$3({}, joined.q.joinedShapes), {
|
|
1184
|
+
[baseQuery2.q.as || baseQuery2.table]: baseQuery2.q.shape
|
|
1144
1185
|
});
|
|
1145
|
-
return
|
|
1146
|
-
},
|
|
1147
|
-
reverseJoin
|
|
1148
|
-
return joinQuery(fromQuery, pqb.getQueryAs(fromQuery), pqb.getQueryAs(toQuery));
|
|
1149
|
-
},
|
|
1186
|
+
return joined;
|
|
1187
|
+
}),
|
|
1188
|
+
reverseJoin,
|
|
1150
1189
|
modifyRelatedQuery(relationQuery) {
|
|
1151
1190
|
const ref = {};
|
|
1152
1191
|
relationQuery._afterCreate([], async (result) => {
|
|
@@ -1156,15 +1195,15 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1156
1195
|
"Creating multiple `hasAndBelongsToMany` records is not yet supported"
|
|
1157
1196
|
);
|
|
1158
1197
|
}
|
|
1159
|
-
const
|
|
1160
|
-
|
|
1198
|
+
const baseQuery2 = ref.q.clone();
|
|
1199
|
+
baseQuery2.q.select = selectPrimaryKeysAsForeignKeys;
|
|
1161
1200
|
const data = {};
|
|
1162
1201
|
for (let i = 0; i < throughLen; i++) {
|
|
1163
1202
|
data[throughForeignKeys[i]] = result[0][throughPrimaryKeys[i]];
|
|
1164
1203
|
}
|
|
1165
|
-
const createdCount = await subQuery.count()._createFrom(
|
|
1204
|
+
const createdCount = await subQuery.count()._createFrom(baseQuery2, data);
|
|
1166
1205
|
if (createdCount === 0) {
|
|
1167
|
-
throw new pqb.NotFoundError(
|
|
1206
|
+
throw new pqb.NotFoundError(baseQuery2);
|
|
1168
1207
|
}
|
|
1169
1208
|
});
|
|
1170
1209
|
return (q) => {
|
|
@@ -1586,10 +1625,23 @@ const makeRelationQuery = (table, relationName, data, q) => {
|
|
|
1586
1625
|
get() {
|
|
1587
1626
|
var _a;
|
|
1588
1627
|
const toTable = q.clone();
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1628
|
+
let query;
|
|
1629
|
+
if (this.q.isSubQuery) {
|
|
1630
|
+
query = toTable;
|
|
1631
|
+
query.q.isSubQuery = true;
|
|
1632
|
+
} else {
|
|
1633
|
+
query = toTable._all()._where({
|
|
1634
|
+
EXISTS: {
|
|
1635
|
+
args: [data.reverseJoin(this, toTable)]
|
|
1636
|
+
}
|
|
1637
|
+
});
|
|
1638
|
+
}
|
|
1639
|
+
if (this.q.relChain) {
|
|
1640
|
+
query.q.relChain = [...this.q.relChain, this];
|
|
1641
|
+
query.q.returnType = "all";
|
|
1642
|
+
} else {
|
|
1643
|
+
query.q.relChain = [this];
|
|
1644
|
+
}
|
|
1593
1645
|
query.q.joinedShapes = __spreadValues$2({
|
|
1594
1646
|
[pqb.getQueryAs(this)]: this.q.shape
|
|
1595
1647
|
}, this.q.joinedShapes);
|
|
@@ -1784,27 +1836,13 @@ const createRepo = (table, methods) => {
|
|
|
1784
1836
|
});
|
|
1785
1837
|
};
|
|
1786
1838
|
|
|
1787
|
-
Object.defineProperty(exports, 'OrchidOrmError', {
|
|
1788
|
-
enumerable: true,
|
|
1789
|
-
get: function () { return pqb.OrchidOrmError; }
|
|
1790
|
-
});
|
|
1791
|
-
Object.defineProperty(exports, 'OrchidOrmInternalError', {
|
|
1792
|
-
enumerable: true,
|
|
1793
|
-
get: function () { return pqb.OrchidOrmInternalError; }
|
|
1794
|
-
});
|
|
1795
|
-
Object.defineProperty(exports, 'columnTypes', {
|
|
1796
|
-
enumerable: true,
|
|
1797
|
-
get: function () { return pqb.columnTypes; }
|
|
1798
|
-
});
|
|
1799
|
-
Object.defineProperty(exports, 'raw', {
|
|
1800
|
-
enumerable: true,
|
|
1801
|
-
get: function () { return pqb.raw; }
|
|
1802
|
-
});
|
|
1803
|
-
Object.defineProperty(exports, 'testTransaction', {
|
|
1804
|
-
enumerable: true,
|
|
1805
|
-
get: function () { return pqb.testTransaction; }
|
|
1806
|
-
});
|
|
1807
1839
|
exports.createBaseTable = createBaseTable;
|
|
1808
1840
|
exports.createRepo = createRepo;
|
|
1809
1841
|
exports.orchidORM = orchidORM;
|
|
1842
|
+
Object.keys(pqb).forEach(function (k) {
|
|
1843
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
1844
|
+
enumerable: true,
|
|
1845
|
+
get: function () { return pqb[k]; }
|
|
1846
|
+
});
|
|
1847
|
+
});
|
|
1810
1848
|
//# sourceMappingURL=index.js.map
|