orchid-orm 1.37.5 → 1.37.7
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 +1 -1
- package/dist/index.js +72 -178
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -178
- package/dist/index.mjs.map +1 -1
- package/dist/migrations.js +248 -521
- package/dist/migrations.js.map +1 -1
- package/dist/migrations.mjs +248 -521
- package/dist/migrations.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -710,4 +710,4 @@ declare const createRepo: <T extends Query, Methods extends MethodsBase<T>>(tabl
|
|
|
710
710
|
shape: T['shape'];
|
|
711
711
|
}>(q: Q) => Query & Q & MapMethods<T, Methods>) & T, Methods>;
|
|
712
712
|
|
|
713
|
-
export { BaseTableClass, BaseTableInstance, Insertable, MapMethods, MapQueryMethods, MethodsBase, ORMTableInput, ORMTableInputToQueryBuilder, OrchidORM, Queryable, Repo, ScopeFn, Selectable, SetColumnsResult, Table, TableClass, TableClasses, TableInfo, TableToDb, Updatable, createBaseTable, createRepo, orchidORM };
|
|
713
|
+
export { type BaseTableClass, type BaseTableInstance, type Insertable, type MapMethods, type MapQueryMethods, type MethodsBase, type ORMTableInput, type ORMTableInputToQueryBuilder, type OrchidORM, type Queryable, type Repo, type ScopeFn, type Selectable, type SetColumnsResult, type Table, type TableClass, type TableClasses, type TableInfo, type TableToDb, type Updatable, createBaseTable, createRepo, orchidORM };
|
package/dist/index.js
CHANGED
|
@@ -59,33 +59,28 @@ function createBaseTable({
|
|
|
59
59
|
return this._pkeySchema === void 0 ? this._pkeySchema = schemaConfig.pkeySchema.call(this) : this._pkeySchema;
|
|
60
60
|
}
|
|
61
61
|
static getFilePath() {
|
|
62
|
-
if (filePath)
|
|
63
|
-
return filePath;
|
|
62
|
+
if (filePath) return filePath;
|
|
64
63
|
if (typeof filePathOrStack === "string") {
|
|
65
64
|
return filePath = filePathOrStack;
|
|
66
65
|
}
|
|
67
66
|
filePath = orchidCore.getCallerFilePath(filePathOrStack);
|
|
68
|
-
if (filePath)
|
|
69
|
-
return filePath;
|
|
67
|
+
if (filePath) return filePath;
|
|
70
68
|
throw new Error(
|
|
71
69
|
`Failed to determine file path of a base table. Please set the \`filePath\` option of \`createBaseTable\` manually.`
|
|
72
70
|
);
|
|
73
71
|
}
|
|
74
72
|
static instance() {
|
|
75
|
-
|
|
76
|
-
return (_a2 = this._instance) != null ? _a2 : this._instance = new this();
|
|
73
|
+
return this._instance ?? (this._instance = new this());
|
|
77
74
|
}
|
|
78
75
|
clone() {
|
|
79
76
|
return this;
|
|
80
77
|
}
|
|
81
78
|
getFilePath() {
|
|
82
|
-
if (this.filePath)
|
|
83
|
-
return this.filePath;
|
|
79
|
+
if (this.filePath) return this.filePath;
|
|
84
80
|
if (typeof filePathOrStack === "string")
|
|
85
81
|
return this.filePath = filePathOrStack;
|
|
86
82
|
const filePath2 = orchidCore.getCallerFilePath(filePathOrStack);
|
|
87
|
-
if (filePath2)
|
|
88
|
-
return this.filePath = filePath2;
|
|
83
|
+
if (filePath2) return this.filePath = filePath2;
|
|
89
84
|
throw new Error(
|
|
90
85
|
`Failed to determine file path for table ${this.constructor.name}. Please set \`filePath\` property manually`
|
|
91
86
|
);
|
|
@@ -97,8 +92,7 @@ function createBaseTable({
|
|
|
97
92
|
if (this.snakeCase) {
|
|
98
93
|
for (const key in shape) {
|
|
99
94
|
const column = shape[key];
|
|
100
|
-
if (column.data.name)
|
|
101
|
-
continue;
|
|
95
|
+
if (column.data.name) continue;
|
|
102
96
|
const snakeName = orchidCore.toSnakeCase(key);
|
|
103
97
|
if (snakeName !== key) {
|
|
104
98
|
column.data.name = snakeName;
|
|
@@ -152,20 +146,17 @@ function createBaseTable({
|
|
|
152
146
|
}
|
|
153
147
|
|
|
154
148
|
const getThroughRelation = (table, through) => {
|
|
155
|
-
|
|
156
|
-
return (_a = table.relations[through]) == null ? void 0 : _a.relationConfig;
|
|
149
|
+
return table.relations[through]?.relationConfig;
|
|
157
150
|
};
|
|
158
151
|
const getSourceRelation = (throughRelation, source) => {
|
|
159
|
-
|
|
160
|
-
return (_a = throughRelation.query.relations[source]) == null ? void 0 : _a.relationConfig;
|
|
152
|
+
return throughRelation.query.relations[source]?.relationConfig;
|
|
161
153
|
};
|
|
162
154
|
const hasRelationHandleCreate = (q, ctx, item, rowIndex, key, primaryKeys, nestedInsert) => {
|
|
163
155
|
const value = item[key];
|
|
164
156
|
if ((!value.create || Array.isArray(value.create) && value.create.length === 0) && (!value.connect || Array.isArray(value.connect) && value.connect.length === 0) && (!value.connectOrCreate || Array.isArray(value.connectOrCreate) && value.connectOrCreate.length === 0))
|
|
165
157
|
return;
|
|
166
158
|
const store = ctx;
|
|
167
|
-
if (!store.hasRelation)
|
|
168
|
-
store.hasRelation = {};
|
|
159
|
+
if (!store.hasRelation) store.hasRelation = {};
|
|
169
160
|
const values = [rowIndex, value];
|
|
170
161
|
if (store.hasRelation[key]) {
|
|
171
162
|
store.hasRelation[key].push(values);
|
|
@@ -283,8 +274,7 @@ class BelongsToVirtualColumn extends pqb.VirtualColumn {
|
|
|
283
274
|
return index;
|
|
284
275
|
});
|
|
285
276
|
const store = ctx;
|
|
286
|
-
if (!store.belongsTo)
|
|
287
|
-
store.belongsTo = {};
|
|
277
|
+
if (!store.belongsTo) store.belongsTo = {};
|
|
288
278
|
const values = [rowIndex, columnIndexes, item[key]];
|
|
289
279
|
if (store.belongsTo[key]) {
|
|
290
280
|
store.belongsTo[key].push(values);
|
|
@@ -389,8 +379,7 @@ const nestedInsert$3 = ({ query, primaryKeys }) => {
|
|
|
389
379
|
items.length = 0;
|
|
390
380
|
for (const item of data) {
|
|
391
381
|
if (item.connectOrCreate) {
|
|
392
|
-
if (!connectOrCreated[connectOrCreatedI++])
|
|
393
|
-
items.push(item);
|
|
382
|
+
if (!connectOrCreated[connectOrCreatedI++]) items.push(item);
|
|
394
383
|
} else if (item.create) {
|
|
395
384
|
items.push(item);
|
|
396
385
|
}
|
|
@@ -432,7 +421,6 @@ const nestedInsert$3 = ({ query, primaryKeys }) => {
|
|
|
432
421
|
};
|
|
433
422
|
const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
434
423
|
return (q, update, params, state) => {
|
|
435
|
-
var _a;
|
|
436
424
|
if (params.upsert && pqb.isQueryReturnsAll(q)) {
|
|
437
425
|
throw new Error("`upsert` option is not allowed in a batch update");
|
|
438
426
|
}
|
|
@@ -450,8 +438,8 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
|
450
438
|
if (primaryKey in params.set) {
|
|
451
439
|
update[foreignKeys[i]] = params.set[primaryKey];
|
|
452
440
|
} else {
|
|
453
|
-
(loadPrimaryKeys
|
|
454
|
-
(loadForeignKeys
|
|
441
|
+
(loadPrimaryKeys ?? (loadPrimaryKeys = [])).push(primaryKey);
|
|
442
|
+
(loadForeignKeys ?? (loadForeignKeys = [])).push(foreignKeys[i]);
|
|
455
443
|
}
|
|
456
444
|
}
|
|
457
445
|
if (loadPrimaryKeys) {
|
|
@@ -487,7 +475,7 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
|
487
475
|
selectIfNotSelected(q, foreignKeys);
|
|
488
476
|
}
|
|
489
477
|
if (upsert) {
|
|
490
|
-
(
|
|
478
|
+
(state.queries ?? (state.queries = [])).push(async (queryResult) => {
|
|
491
479
|
const row = queryResult.rows[0];
|
|
492
480
|
let obj = {};
|
|
493
481
|
for (let i = 0; i < len; i++) {
|
|
@@ -534,15 +522,13 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
|
534
522
|
row = void 0;
|
|
535
523
|
break;
|
|
536
524
|
} else {
|
|
537
|
-
(row
|
|
525
|
+
(row ?? (row = [])).push(id);
|
|
538
526
|
}
|
|
539
527
|
}
|
|
540
|
-
if (row)
|
|
541
|
-
ids.push(row);
|
|
528
|
+
if (row) ids.push(row);
|
|
542
529
|
}
|
|
543
530
|
}
|
|
544
|
-
if (!
|
|
545
|
-
return;
|
|
531
|
+
if (!ids?.length) return;
|
|
546
532
|
const t = query.whereIn(
|
|
547
533
|
primaryKeys,
|
|
548
534
|
ids
|
|
@@ -557,22 +543,6 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
|
557
543
|
};
|
|
558
544
|
};
|
|
559
545
|
|
|
560
|
-
var __defProp$4 = Object.defineProperty;
|
|
561
|
-
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
562
|
-
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
563
|
-
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
564
|
-
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
565
|
-
var __spreadValues$4 = (a, b) => {
|
|
566
|
-
for (var prop in b || (b = {}))
|
|
567
|
-
if (__hasOwnProp$4.call(b, prop))
|
|
568
|
-
__defNormalProp$4(a, prop, b[prop]);
|
|
569
|
-
if (__getOwnPropSymbols$4)
|
|
570
|
-
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
571
|
-
if (__propIsEnum$4.call(b, prop))
|
|
572
|
-
__defNormalProp$4(a, prop, b[prop]);
|
|
573
|
-
}
|
|
574
|
-
return a;
|
|
575
|
-
};
|
|
576
546
|
class HasOneVirtualColumn extends pqb.VirtualColumn {
|
|
577
547
|
constructor(schema, key, state) {
|
|
578
548
|
super(schema);
|
|
@@ -744,7 +714,9 @@ const nestedInsert$2 = ({ query, primaryKeys, foreignKeys }) => {
|
|
|
744
714
|
if (items.length) {
|
|
745
715
|
for (let i = 0, len = items.length; i < len; i++) {
|
|
746
716
|
const [selfData, item] = items[i];
|
|
747
|
-
const data2 =
|
|
717
|
+
const data2 = {
|
|
718
|
+
..."create" in item ? item.create : item.connectOrCreate.create
|
|
719
|
+
};
|
|
748
720
|
for (let i2 = 0; i2 < primaryKeys.length; i2++) {
|
|
749
721
|
data2[foreignKeys[i2]] = selfData[primaryKeys[i2]];
|
|
750
722
|
}
|
|
@@ -773,7 +745,7 @@ const nestedUpdate$2 = ({ query, primaryKeys, foreignKeys }) => {
|
|
|
773
745
|
await pqb._queryUpdate(currentRelationsQuery, setNulls);
|
|
774
746
|
const record = data[0];
|
|
775
747
|
if (params.create) {
|
|
776
|
-
const obj =
|
|
748
|
+
const obj = { ...params.create };
|
|
777
749
|
for (let i = 0; i < len; i++) {
|
|
778
750
|
obj[foreignKeys[i]] = record[primaryKeys[i]];
|
|
779
751
|
}
|
|
@@ -807,7 +779,7 @@ const nestedUpdate$2 = ({ query, primaryKeys, foreignKeys }) => {
|
|
|
807
779
|
if (!updatedIds.some(
|
|
808
780
|
(updated) => updated.every((value, i) => value === ids2[i])
|
|
809
781
|
)) {
|
|
810
|
-
const obj =
|
|
782
|
+
const obj = { ...data2 };
|
|
811
783
|
for (let i = 0; i < len; i++) {
|
|
812
784
|
obj[foreignKeys[i]] = ids2[i];
|
|
813
785
|
}
|
|
@@ -821,22 +793,6 @@ const nestedUpdate$2 = ({ query, primaryKeys, foreignKeys }) => {
|
|
|
821
793
|
};
|
|
822
794
|
};
|
|
823
795
|
|
|
824
|
-
var __defProp$3 = Object.defineProperty;
|
|
825
|
-
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
826
|
-
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
827
|
-
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
828
|
-
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
829
|
-
var __spreadValues$3 = (a, b) => {
|
|
830
|
-
for (var prop in b || (b = {}))
|
|
831
|
-
if (__hasOwnProp$3.call(b, prop))
|
|
832
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
833
|
-
if (__getOwnPropSymbols$3)
|
|
834
|
-
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
835
|
-
if (__propIsEnum$3.call(b, prop))
|
|
836
|
-
__defNormalProp$3(a, prop, b[prop]);
|
|
837
|
-
}
|
|
838
|
-
return a;
|
|
839
|
-
};
|
|
840
796
|
class HasManyVirtualColumn extends pqb.VirtualColumn {
|
|
841
797
|
constructor(schema, key, state) {
|
|
842
798
|
super(schema);
|
|
@@ -1056,13 +1012,19 @@ const nestedInsert$1 = ({ query, primaryKeys, foreignKeys }) => {
|
|
|
1056
1012
|
}
|
|
1057
1013
|
if (create) {
|
|
1058
1014
|
for (const item of create) {
|
|
1059
|
-
records.push(
|
|
1015
|
+
records.push({
|
|
1016
|
+
...item,
|
|
1017
|
+
...obj
|
|
1018
|
+
});
|
|
1060
1019
|
}
|
|
1061
1020
|
}
|
|
1062
1021
|
if (connectOrCreate) {
|
|
1063
1022
|
for (const item of connectOrCreate) {
|
|
1064
1023
|
if (connected[connectedI++] === 0) {
|
|
1065
|
-
records.push(
|
|
1024
|
+
records.push({
|
|
1025
|
+
...item.create,
|
|
1026
|
+
...obj
|
|
1027
|
+
});
|
|
1066
1028
|
}
|
|
1067
1029
|
}
|
|
1068
1030
|
}
|
|
@@ -1074,7 +1036,6 @@ const nestedInsert$1 = ({ query, primaryKeys, foreignKeys }) => {
|
|
|
1074
1036
|
const nestedUpdate$1 = ({ query, primaryKeys, foreignKeys }) => {
|
|
1075
1037
|
const len = primaryKeys.length;
|
|
1076
1038
|
return async (_, data, params) => {
|
|
1077
|
-
var _a;
|
|
1078
1039
|
const t = query.clone();
|
|
1079
1040
|
if (params.create) {
|
|
1080
1041
|
const obj = {};
|
|
@@ -1082,7 +1043,10 @@ const nestedUpdate$1 = ({ query, primaryKeys, foreignKeys }) => {
|
|
|
1082
1043
|
obj[foreignKeys[i]] = data[0][primaryKeys[i]];
|
|
1083
1044
|
}
|
|
1084
1045
|
await t.insertMany(
|
|
1085
|
-
params.create.map((create) =>
|
|
1046
|
+
params.create.map((create) => ({
|
|
1047
|
+
...create,
|
|
1048
|
+
...obj
|
|
1049
|
+
}))
|
|
1086
1050
|
);
|
|
1087
1051
|
delete t.q[pqb.toSQLCacheKey];
|
|
1088
1052
|
}
|
|
@@ -1122,7 +1086,7 @@ const nestedUpdate$1 = ({ query, primaryKeys, foreignKeys }) => {
|
|
|
1122
1086
|
const q = getWhereForNestedUpdate(
|
|
1123
1087
|
t,
|
|
1124
1088
|
data,
|
|
1125
|
-
params.delete ||
|
|
1089
|
+
params.delete || params.update?.where,
|
|
1126
1090
|
primaryKeys,
|
|
1127
1091
|
foreignKeys
|
|
1128
1092
|
);
|
|
@@ -1135,25 +1099,6 @@ const nestedUpdate$1 = ({ query, primaryKeys, foreignKeys }) => {
|
|
|
1135
1099
|
};
|
|
1136
1100
|
};
|
|
1137
1101
|
|
|
1138
|
-
var __defProp$2 = Object.defineProperty;
|
|
1139
|
-
var __defProps$1 = Object.defineProperties;
|
|
1140
|
-
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
1141
|
-
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
1142
|
-
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
1143
|
-
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
1144
|
-
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1145
|
-
var __spreadValues$2 = (a, b) => {
|
|
1146
|
-
for (var prop in b || (b = {}))
|
|
1147
|
-
if (__hasOwnProp$2.call(b, prop))
|
|
1148
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
1149
|
-
if (__getOwnPropSymbols$2)
|
|
1150
|
-
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
1151
|
-
if (__propIsEnum$2.call(b, prop))
|
|
1152
|
-
__defNormalProp$2(a, prop, b[prop]);
|
|
1153
|
-
}
|
|
1154
|
-
return a;
|
|
1155
|
-
};
|
|
1156
|
-
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
1157
1102
|
class HasAndBelongsToManyVirtualColumn extends pqb.VirtualColumn {
|
|
1158
1103
|
constructor(joinTable, schema, key, state) {
|
|
1159
1104
|
super(schema);
|
|
@@ -1185,10 +1130,9 @@ class HasAndBelongsToManyVirtualColumn extends pqb.VirtualColumn {
|
|
|
1185
1130
|
}
|
|
1186
1131
|
}
|
|
1187
1132
|
const removeColumnName = (column) => {
|
|
1188
|
-
if (!column.data.name)
|
|
1189
|
-
return column;
|
|
1133
|
+
if (!column.data.name) return column;
|
|
1190
1134
|
const cloned = Object.create(column);
|
|
1191
|
-
cloned.data =
|
|
1135
|
+
cloned.data = { ...column.data, name: void 0 };
|
|
1192
1136
|
return cloned;
|
|
1193
1137
|
};
|
|
1194
1138
|
const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query) => {
|
|
@@ -1200,13 +1144,11 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1200
1144
|
const throughPrimaryKeys = options.through.references;
|
|
1201
1145
|
const { snakeCase } = table.internal;
|
|
1202
1146
|
const foreignKeysFull = foreignKeys.map((key, i) => {
|
|
1203
|
-
if (snakeCase)
|
|
1204
|
-
key = foreignKeys[i] = orchidCore.toSnakeCase(key);
|
|
1147
|
+
if (snakeCase) key = foreignKeys[i] = orchidCore.toSnakeCase(key);
|
|
1205
1148
|
return `${joinTable}.${key}`;
|
|
1206
1149
|
});
|
|
1207
1150
|
const throughForeignKeysFull = throughForeignKeys.map((key, i) => {
|
|
1208
|
-
if (snakeCase)
|
|
1209
|
-
key = throughForeignKeys[i] = orchidCore.toSnakeCase(key);
|
|
1151
|
+
if (snakeCase) key = throughForeignKeys[i] = orchidCore.toSnakeCase(key);
|
|
1210
1152
|
return `${joinTable}.${key}`;
|
|
1211
1153
|
});
|
|
1212
1154
|
const foreignTable = pqb.getQueryAs(query);
|
|
@@ -1230,9 +1172,10 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1230
1172
|
);
|
|
1231
1173
|
}
|
|
1232
1174
|
baseQuery.shape = shape;
|
|
1233
|
-
baseQuery.q =
|
|
1175
|
+
baseQuery.q = {
|
|
1176
|
+
...baseQuery.q,
|
|
1234
1177
|
shape: baseQuery.shape
|
|
1235
|
-
}
|
|
1178
|
+
};
|
|
1236
1179
|
const subQuery = Object.create(baseQuery);
|
|
1237
1180
|
const state = {
|
|
1238
1181
|
relatedTableQuery: query,
|
|
@@ -1274,9 +1217,10 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1274
1217
|
baseQuery2,
|
|
1275
1218
|
pqb.getQueryAs(baseQuery2),
|
|
1276
1219
|
foreignAs,
|
|
1277
|
-
|
|
1220
|
+
{
|
|
1221
|
+
...baseQuery2.q.joinedShapes,
|
|
1278
1222
|
[foreignAs]: joiningQuery.q.shape
|
|
1279
|
-
}
|
|
1223
|
+
}
|
|
1280
1224
|
);
|
|
1281
1225
|
};
|
|
1282
1226
|
return {
|
|
@@ -1309,9 +1253,10 @@ const makeHasAndBelongsToManyMethod = (table, qb, relation, relationName, query)
|
|
|
1309
1253
|
joiningQuery,
|
|
1310
1254
|
pqb.getQueryAs(baseQuery2),
|
|
1311
1255
|
pqb.getQueryAs(joiningQuery),
|
|
1312
|
-
|
|
1256
|
+
{
|
|
1257
|
+
...joiningQuery.q.joinedShapes,
|
|
1313
1258
|
[baseQuery2.q.as || baseQuery2.table]: baseQuery2.q.shape
|
|
1314
|
-
}
|
|
1259
|
+
}
|
|
1315
1260
|
)
|
|
1316
1261
|
),
|
|
1317
1262
|
reverseJoin,
|
|
@@ -1382,7 +1327,7 @@ const insertToJoinTable = (state, joinTableTransaction, data, idsRows) => {
|
|
|
1382
1327
|
obj[state.foreignKeys[i]] = item[state.primaryKeys[i]];
|
|
1383
1328
|
}
|
|
1384
1329
|
for (const ids of idsRows) {
|
|
1385
|
-
const record =
|
|
1330
|
+
const record = { ...obj };
|
|
1386
1331
|
for (let i = 0; i < throughLen; i++) {
|
|
1387
1332
|
record[state.throughForeignKeys[i]] = ids[i];
|
|
1388
1333
|
}
|
|
@@ -1525,7 +1470,7 @@ const nestedInsert = ({
|
|
|
1525
1470
|
obj[foreignKeys[i]] = selfData[primaryKeys[i]];
|
|
1526
1471
|
}
|
|
1527
1472
|
for (const relationData of relationKeys) {
|
|
1528
|
-
const record =
|
|
1473
|
+
const record = { ...obj };
|
|
1529
1474
|
for (let i = 0; i < throughLen; i++) {
|
|
1530
1475
|
record[throughForeignKeys[i]] = relationData[throughPrimaryKeys[i]];
|
|
1531
1476
|
}
|
|
@@ -1551,7 +1496,7 @@ const nestedUpdate = (state) => {
|
|
|
1551
1496
|
obj[state.foreignKeys[i]] = item[state.primaryKeys[i]];
|
|
1552
1497
|
}
|
|
1553
1498
|
for (const ids of idsRows) {
|
|
1554
|
-
const record =
|
|
1499
|
+
const record = { ...obj };
|
|
1555
1500
|
for (let i = 0; i < throughLen; i++) {
|
|
1556
1501
|
record[state.throughForeignKeys[i]] = ids[i];
|
|
1557
1502
|
}
|
|
@@ -1625,7 +1570,6 @@ const nestedUpdate = (state) => {
|
|
|
1625
1570
|
};
|
|
1626
1571
|
|
|
1627
1572
|
const applyRelations = (qb, tables, result) => {
|
|
1628
|
-
var _a;
|
|
1629
1573
|
const tableEntries = Object.entries(tables);
|
|
1630
1574
|
const delayedRelations = /* @__PURE__ */ new Map();
|
|
1631
1575
|
for (const name in tables) {
|
|
@@ -1683,13 +1627,12 @@ const applyRelations = (qb, tables, result) => {
|
|
|
1683
1627
|
for (const key in value) {
|
|
1684
1628
|
for (const item of value[key]) {
|
|
1685
1629
|
const { relation } = item;
|
|
1686
|
-
if (item.dbTable.relations[item.relationName])
|
|
1687
|
-
continue;
|
|
1630
|
+
if (item.dbTable.relations[item.relationName]) continue;
|
|
1688
1631
|
const as = item.dbTable.definedAs;
|
|
1689
1632
|
let message = `Cannot define a \`${item.relationName}\` relation on \`${as}\``;
|
|
1690
1633
|
const table = result[as];
|
|
1691
1634
|
const { through, source } = relation.options;
|
|
1692
|
-
const throughRel =
|
|
1635
|
+
const throughRel = table.relations[through]?.relationConfig;
|
|
1693
1636
|
if (through && !throughRel) {
|
|
1694
1637
|
message += `: cannot find \`${through}\` relation required by the \`through\` option`;
|
|
1695
1638
|
} else if (source && throughRel && !throughRel.table.relations[source]) {
|
|
@@ -1713,7 +1656,6 @@ const delayRelation = (delayedRelations, table, relationName, data) => {
|
|
|
1713
1656
|
}
|
|
1714
1657
|
};
|
|
1715
1658
|
const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, delayedRelations) => {
|
|
1716
|
-
var _a;
|
|
1717
1659
|
const baseQuery = Object.create(otherDbTable);
|
|
1718
1660
|
baseQuery.baseQuery = baseQuery;
|
|
1719
1661
|
const query = (relation.options.scope ? relation.options.scope(baseQuery) : baseQuery).as(relationName);
|
|
@@ -1774,9 +1716,8 @@ const applyRelation = (qb, { relationName, relation, dbTable, otherDbTable }, de
|
|
|
1774
1716
|
};
|
|
1775
1717
|
dbTable.relations[relationName] = query;
|
|
1776
1718
|
const tableRelations = delayedRelations.get(dbTable);
|
|
1777
|
-
if (!tableRelations)
|
|
1778
|
-
|
|
1779
|
-
(_a = tableRelations[relationName]) == null ? void 0 : _a.forEach((data2) => {
|
|
1719
|
+
if (!tableRelations) return;
|
|
1720
|
+
tableRelations[relationName]?.forEach((data2) => {
|
|
1780
1721
|
applyRelation(qb, data2, delayedRelations);
|
|
1781
1722
|
});
|
|
1782
1723
|
};
|
|
@@ -1794,50 +1735,13 @@ function isInTransaction() {
|
|
|
1794
1735
|
return this.$queryBuilder.isInTransaction();
|
|
1795
1736
|
}
|
|
1796
1737
|
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
var __spreadValues$1 = (a, b) => {
|
|
1805
|
-
for (var prop in b || (b = {}))
|
|
1806
|
-
if (__hasOwnProp$1.call(b, prop))
|
|
1807
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
1808
|
-
if (__getOwnPropSymbols$1)
|
|
1809
|
-
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
1810
|
-
if (__propIsEnum$1.call(b, prop))
|
|
1811
|
-
__defNormalProp$1(a, prop, b[prop]);
|
|
1812
|
-
}
|
|
1813
|
-
return a;
|
|
1814
|
-
};
|
|
1815
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
1816
|
-
var __objRest = (source, exclude) => {
|
|
1817
|
-
var target = {};
|
|
1818
|
-
for (var prop in source)
|
|
1819
|
-
if (__hasOwnProp$1.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
1820
|
-
target[prop] = source[prop];
|
|
1821
|
-
if (source != null && __getOwnPropSymbols$1)
|
|
1822
|
-
for (var prop of __getOwnPropSymbols$1(source)) {
|
|
1823
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$1.call(source, prop))
|
|
1824
|
-
target[prop] = source[prop];
|
|
1825
|
-
}
|
|
1826
|
-
return target;
|
|
1827
|
-
};
|
|
1828
|
-
const orchidORM = (_a, tables) => {
|
|
1829
|
-
var _b = _a, {
|
|
1830
|
-
log,
|
|
1831
|
-
logger,
|
|
1832
|
-
autoPreparedStatements,
|
|
1833
|
-
noPrimaryKey = "error"
|
|
1834
|
-
} = _b, options = __objRest(_b, [
|
|
1835
|
-
"log",
|
|
1836
|
-
"logger",
|
|
1837
|
-
"autoPreparedStatements",
|
|
1838
|
-
"noPrimaryKey"
|
|
1839
|
-
]);
|
|
1840
|
-
var _a2;
|
|
1738
|
+
const orchidORM = ({
|
|
1739
|
+
log,
|
|
1740
|
+
logger,
|
|
1741
|
+
autoPreparedStatements,
|
|
1742
|
+
noPrimaryKey = "error",
|
|
1743
|
+
...options
|
|
1744
|
+
}, tables) => {
|
|
1841
1745
|
const commonOptions = {
|
|
1842
1746
|
log,
|
|
1843
1747
|
logger,
|
|
@@ -1884,7 +1788,8 @@ const orchidORM = (_a, tables) => {
|
|
|
1884
1788
|
const tableClass = tables[key];
|
|
1885
1789
|
const table = tableClass.instance();
|
|
1886
1790
|
tableInstances[key] = table;
|
|
1887
|
-
const options2 =
|
|
1791
|
+
const options2 = {
|
|
1792
|
+
...commonOptions,
|
|
1888
1793
|
schema: table.schema,
|
|
1889
1794
|
language: table.language,
|
|
1890
1795
|
scopes: table.scopes,
|
|
@@ -1894,7 +1799,7 @@ const orchidORM = (_a, tables) => {
|
|
|
1894
1799
|
noPrimaryKey: table.noPrimaryKey ? "ignore" : void 0,
|
|
1895
1800
|
computed: table.computed,
|
|
1896
1801
|
nowSQL: tableClass.nowSQL
|
|
1897
|
-
}
|
|
1802
|
+
};
|
|
1898
1803
|
const dbTable = new pqb.Db(
|
|
1899
1804
|
adapter,
|
|
1900
1805
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1904,7 +1809,7 @@ const orchidORM = (_a, tables) => {
|
|
|
1904
1809
|
table.types,
|
|
1905
1810
|
transactionStorage,
|
|
1906
1811
|
options2,
|
|
1907
|
-
|
|
1812
|
+
table.constructor.prototype.tableData ?? orchidCore.emptyObject
|
|
1908
1813
|
);
|
|
1909
1814
|
dbTable.definedAs = key;
|
|
1910
1815
|
dbTable.db = result;
|
|
@@ -1923,24 +1828,13 @@ const orchidORM = (_a, tables) => {
|
|
|
1923
1828
|
return result;
|
|
1924
1829
|
};
|
|
1925
1830
|
|
|
1926
|
-
var __defProp = Object.defineProperty;
|
|
1927
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
1928
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1929
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
1930
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1931
|
-
var __spreadValues = (a, b) => {
|
|
1932
|
-
for (var prop in b || (b = {}))
|
|
1933
|
-
if (__hasOwnProp.call(b, prop))
|
|
1934
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1935
|
-
if (__getOwnPropSymbols)
|
|
1936
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
1937
|
-
if (__propIsEnum.call(b, prop))
|
|
1938
|
-
__defNormalProp(a, prop, b[prop]);
|
|
1939
|
-
}
|
|
1940
|
-
return a;
|
|
1941
|
-
};
|
|
1942
1831
|
const createRepo = (table, methods) => {
|
|
1943
|
-
const queryMethods =
|
|
1832
|
+
const queryMethods = {
|
|
1833
|
+
...methods.queryMethods,
|
|
1834
|
+
...methods.queryOneMethods,
|
|
1835
|
+
...methods.queryWithWhereMethods,
|
|
1836
|
+
...methods.queryOneWithWhereMethods
|
|
1837
|
+
};
|
|
1944
1838
|
const plainMethods = methods.methods;
|
|
1945
1839
|
const repo = (q2) => {
|
|
1946
1840
|
const proto = Object.create(q2.baseQuery);
|