orchid-orm 1.14.0 → 1.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +193 -49
- package/dist/index.js +15 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -27
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { columnTypes, QueryHooks, getColumnTypes, addQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, getQueryAs, toSQLCacheKey, OrchidOrmInternalError, NotFoundError,
|
|
1
|
+
import { columnTypes, QueryHooks, getColumnTypes, addQueryOn, VirtualColumn, pushQueryValue, isQueryReturnsAll, getQueryAs, toSQLCacheKey, OrchidOrmInternalError, NotFoundError, Adapter, Db, anyShape, getClonedQueryData } from 'pqb';
|
|
2
2
|
export { OrchidOrmError, OrchidOrmInternalError, columnTypes, raw, testTransaction } from 'pqb';
|
|
3
3
|
import { getStackTrace, applyMixins, getCallerFilePath, snakeCaseKey, toSnakeCase } from 'orchid-core';
|
|
4
4
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
@@ -177,8 +177,7 @@ const makeBelongsToMethod = (relation, relationName, query) => {
|
|
|
177
177
|
},
|
|
178
178
|
reverseJoin(fromQuery, toQuery) {
|
|
179
179
|
return addQueryOn(fromQuery, toQuery, fromQuery, foreignKey, primaryKey);
|
|
180
|
-
}
|
|
181
|
-
primaryKey
|
|
180
|
+
}
|
|
182
181
|
};
|
|
183
182
|
};
|
|
184
183
|
const nestedInsert$3 = ({ query, primaryKey }) => {
|
|
@@ -301,10 +300,12 @@ const nestedUpdate$3 = ({ query, primaryKey, foreignKey }) => {
|
|
|
301
300
|
};
|
|
302
301
|
|
|
303
302
|
const getThroughRelation = (table, through) => {
|
|
304
|
-
|
|
303
|
+
var _a;
|
|
304
|
+
return (_a = table.relations[through]) == null ? void 0 : _a.relationConfig;
|
|
305
305
|
};
|
|
306
306
|
const getSourceRelation = (throughRelation, source) => {
|
|
307
|
-
|
|
307
|
+
var _a;
|
|
308
|
+
return (_a = throughRelation.table.relations[source]) == null ? void 0 : _a.relationConfig;
|
|
308
309
|
};
|
|
309
310
|
const hasRelationHandleCreate = (q, ctx, item, rowIndex, key, primaryKey, nestedInsert) => {
|
|
310
311
|
const value = item[key];
|
|
@@ -442,8 +443,7 @@ const makeHasOneMethod = (table, relation, relationName, query) => {
|
|
|
442
443
|
);
|
|
443
444
|
}
|
|
444
445
|
);
|
|
445
|
-
}
|
|
446
|
-
primaryKey: sourceRelation.primaryKey
|
|
446
|
+
}
|
|
447
447
|
};
|
|
448
448
|
}
|
|
449
449
|
const { primaryKey, foreignKey } = relation.options;
|
|
@@ -462,7 +462,6 @@ const makeHasOneMethod = (table, relation, relationName, query) => {
|
|
|
462
462
|
reverseJoin(fromQuery, toQuery) {
|
|
463
463
|
return addQueryOn(fromQuery, toQuery, fromQuery, primaryKey, foreignKey);
|
|
464
464
|
},
|
|
465
|
-
primaryKey,
|
|
466
465
|
modifyRelatedQuery(relationQuery) {
|
|
467
466
|
return (query2) => {
|
|
468
467
|
const fromQuery = query2.clone();
|
|
@@ -641,8 +640,7 @@ const makeHasManyMethod = (table, relation, relationName, query) => {
|
|
|
641
640
|
);
|
|
642
641
|
}
|
|
643
642
|
);
|
|
644
|
-
}
|
|
645
|
-
primaryKey: sourceRelation.primaryKey
|
|
643
|
+
}
|
|
646
644
|
};
|
|
647
645
|
}
|
|
648
646
|
const { primaryKey, foreignKey } = relation.options;
|
|
@@ -661,7 +659,6 @@ const makeHasManyMethod = (table, relation, relationName, query) => {
|
|
|
661
659
|
reverseJoin(fromQuery, toQuery) {
|
|
662
660
|
return addQueryOn(fromQuery, toQuery, fromQuery, primaryKey, foreignKey);
|
|
663
661
|
},
|
|
664
|
-
primaryKey,
|
|
665
662
|
modifyRelatedQuery(relationQuery) {
|
|
666
663
|
return (query2) => {
|
|
667
664
|
const fromQuery = query2.clone();
|
|
@@ -695,7 +692,9 @@ const nestedInsert$1 = ({ query, primaryKey, foreignKey }) => {
|
|
|
695
692
|
if (connect.length) {
|
|
696
693
|
await Promise.all(
|
|
697
694
|
connect.flatMap(
|
|
698
|
-
([selfData, { connect: connect2 }]) => t.or(...connect2)._updateOrThrow({
|
|
695
|
+
([selfData, { connect: connect2 }]) => t.or(...connect2)._updateOrThrow({
|
|
696
|
+
[foreignKey]: selfData[primaryKey]
|
|
697
|
+
})
|
|
699
698
|
)
|
|
700
699
|
);
|
|
701
700
|
}
|
|
@@ -913,7 +912,6 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
913
912
|
(q) => q._on(associationForeignKeyFull, `${getQueryAs(toQuery)}.${apk}`)._on(foreignKeyFull, `${getQueryAs(fromQuery)}.${pk}`)
|
|
914
913
|
);
|
|
915
914
|
},
|
|
916
|
-
primaryKey: pk,
|
|
917
915
|
modifyRelatedQuery(relationQuery) {
|
|
918
916
|
const ref = {};
|
|
919
917
|
relationQuery._afterCreate([], async (result) => {
|
|
@@ -1151,6 +1149,7 @@ var __spreadValues$2 = (a, b) => {
|
|
|
1151
1149
|
return a;
|
|
1152
1150
|
};
|
|
1153
1151
|
const applyRelations = (qb, tables, result) => {
|
|
1152
|
+
var _a;
|
|
1154
1153
|
const tableEntries = Object.entries(tables);
|
|
1155
1154
|
const delayedRelations = /* @__PURE__ */ new Map();
|
|
1156
1155
|
for (const name in tables) {
|
|
@@ -1214,7 +1213,7 @@ const applyRelations = (qb, tables, result) => {
|
|
|
1214
1213
|
let message = `Cannot define a \`${item.relationName}\` relation on \`${as}\``;
|
|
1215
1214
|
const table = result[as];
|
|
1216
1215
|
const { through, source } = relation.options;
|
|
1217
|
-
const throughRel = table.relations[through];
|
|
1216
|
+
const throughRel = (_a = table.relations[through]) == null ? void 0 : _a.relationConfig;
|
|
1218
1217
|
if (through && !throughRel) {
|
|
1219
1218
|
message += `: cannot find \`${through}\` relation required by the \`through\` option`;
|
|
1220
1219
|
} else if (source && throughRel && !throughRel.table.relations[source]) {
|
|
@@ -1290,16 +1289,12 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
|
|
|
1290
1289
|
return q;
|
|
1291
1290
|
}
|
|
1292
1291
|
};
|
|
1293
|
-
|
|
1294
|
-
type,
|
|
1295
|
-
key: relationName,
|
|
1292
|
+
baseQuery.relationConfig = {
|
|
1296
1293
|
table: otherDbTable,
|
|
1297
1294
|
query,
|
|
1298
|
-
joinQuery: data.joinQuery
|
|
1299
|
-
primaryKey: data.primaryKey,
|
|
1300
|
-
options: relation.options
|
|
1295
|
+
joinQuery: data.joinQuery
|
|
1301
1296
|
};
|
|
1302
|
-
dbTable.
|
|
1297
|
+
dbTable.relations[relationName] = query;
|
|
1303
1298
|
const tableRelations = delayedRelations.get(dbTable);
|
|
1304
1299
|
if (!tableRelations)
|
|
1305
1300
|
return;
|
|
@@ -1320,12 +1315,6 @@ const makeRelationQuery = (table, relationName, data, q) => {
|
|
|
1320
1315
|
query.q.joinedShapes = __spreadValues$2({
|
|
1321
1316
|
[getQueryAs(this)]: this.q.shape
|
|
1322
1317
|
}, this.q.joinedShapes);
|
|
1323
|
-
query.q[relationQueryKey] = {
|
|
1324
|
-
relationName,
|
|
1325
|
-
sourceQuery: this,
|
|
1326
|
-
relationQuery: toTable,
|
|
1327
|
-
joinQuery: data.joinQuery
|
|
1328
|
-
};
|
|
1329
1318
|
const setQuery = (_a = data.modifyRelatedQuery) == null ? void 0 : _a.call(data, query);
|
|
1330
1319
|
setQuery == null ? void 0 : setQuery(this);
|
|
1331
1320
|
return new Proxy(data.method, {
|