orchid-orm 1.54.1 → 1.55.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/dist/index.d.ts +9 -3
- package/dist/index.js +45 -42
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -34
- package/dist/index.mjs.map +1 -1
- package/dist/migrations.js +12 -12
- package/dist/migrations.js.map +1 -1
- package/dist/migrations.mjs +4 -4
- package/dist/migrations.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { makeColumnTypes, QueryHooks, defaultSchemaConfig, raw, getColumnTypes, parseTableData, _queryHookAfterCreate, _queryHookAfterUpdate, getQueryAs, setQueryObjectValueImmutable, pushQueryOnForOuter, cloneQueryBaseUnscoped, DynamicRawSQL, RawSQL, getShapeFromSelect, _queryWhere, _queryDefaults,
|
|
1
|
+
import { makeColumnTypes, QueryHooks, defaultSchemaConfig, raw, getColumnTypes, parseTableData, _queryHookAfterCreate, _queryHookAfterUpdate, getQueryAs, setQueryObjectValueImmutable, pushQueryOnForOuter, cloneQueryBaseUnscoped, DynamicRawSQL, RawSQL, getShapeFromSelect, _queryWhere, _queryDefaults, VirtualColumn, _queryCreateMany, isQueryReturnsAll, _queryHookBeforeUpdate, _queryFindBy, _queryCreate, _queryRows, _queryUpdate, _queryDelete, _queryUpdateOrThrow, _queryJoinOn, _queryCreateFrom, _queryFindByOptional, _querySelect, _queryWhereExists, _queryTake, _queryTakeOptional, Adapter, _initQueryBuilder, Db, getClonedQueryData } from 'pqb';
|
|
2
2
|
export * from 'pqb';
|
|
3
|
-
import { getStackTrace, applyMixins, getCallerFilePath, snakeCaseKey, toSnakeCase, emptyObject, emptyArray, isExpression, pushQueryValueImmutable, toArray, objectHasValues, pick } from 'orchid-core';
|
|
3
|
+
import { getStackTrace, applyMixins, getCallerFilePath, snakeCaseKey, toSnakeCase, emptyObject, emptyArray, isExpression, getPrimaryKeys, pushQueryValueImmutable, OrchidOrmInternalError, toArray, objectHasValues, NotFoundError, pick } from 'orchid-core';
|
|
4
4
|
export * from 'orchid-core';
|
|
5
5
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
6
6
|
|
|
@@ -183,7 +183,6 @@ const hasRelationHandleUpdate = (q, set, key, primaryKeys, nestedUpdate) => {
|
|
|
183
183
|
const value = set[key];
|
|
184
184
|
if (!value.set && !("upsert" in value) && (!value.add || Array.isArray(value.add) && value.add.length === 0) && (!value.disconnect || Array.isArray(value.disconnect) && value.disconnect.length === 0) && (!value.delete || Array.isArray(value.delete) && value.delete.length === 0) && (!value.update || Array.isArray(value.update.where) && value.update.where.length === 0) && (!value.create || Array.isArray(value.create) && value.create.length === 0))
|
|
185
185
|
return;
|
|
186
|
-
selectIfNotSelected(q, primaryKeys);
|
|
187
186
|
q.q.wrapInTransaction = true;
|
|
188
187
|
_queryHookAfterUpdate(q, primaryKeys, (rows, q2) => {
|
|
189
188
|
return nestedUpdate(
|
|
@@ -637,6 +636,7 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
|
637
636
|
const selectQuery = q2.clone();
|
|
638
637
|
selectQuery.q.type = void 0;
|
|
639
638
|
selectQuery.q.distinct = emptyArray;
|
|
639
|
+
selectIfNotSelected(selectQuery, foreignKeys);
|
|
640
640
|
idsForDelete = await _queryRows(selectQuery);
|
|
641
641
|
for (const foreignKey of foreignKeys) {
|
|
642
642
|
update[foreignKey] = null;
|
|
@@ -644,9 +644,7 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
|
644
644
|
}
|
|
645
645
|
});
|
|
646
646
|
const { upsert } = params;
|
|
647
|
-
if (upsert || params.update || params.delete)
|
|
648
|
-
selectIfNotSelected(q, foreignKeys);
|
|
649
|
-
}
|
|
647
|
+
if (upsert || params.update || params.delete) ;
|
|
650
648
|
if (upsert) {
|
|
651
649
|
(state.queries ?? (state.queries = [])).push(async (queryResult) => {
|
|
652
650
|
const row = queryResult.rows[0];
|
|
@@ -671,7 +669,6 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
|
671
669
|
);
|
|
672
670
|
const collectData = {};
|
|
673
671
|
state.collect = {
|
|
674
|
-
keys: primaryKeys,
|
|
675
672
|
data: collectData
|
|
676
673
|
};
|
|
677
674
|
for (let i = 0; i < len; i++) {
|
|
@@ -680,37 +677,41 @@ const nestedUpdate$3 = ({ query, primaryKeys, foreignKeys, len }) => {
|
|
|
680
677
|
}
|
|
681
678
|
});
|
|
682
679
|
} else if (params.delete || params.update) {
|
|
683
|
-
_queryHookAfterUpdate(
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
680
|
+
_queryHookAfterUpdate(
|
|
681
|
+
q,
|
|
682
|
+
params.update ? foreignKeys : emptyArray,
|
|
683
|
+
async (data) => {
|
|
684
|
+
let ids;
|
|
685
|
+
if (params.delete) {
|
|
686
|
+
ids = idsForDelete;
|
|
687
|
+
} else {
|
|
688
|
+
ids = [];
|
|
689
|
+
for (const item of data) {
|
|
690
|
+
let row;
|
|
691
|
+
for (const foreignKey of foreignKeys) {
|
|
692
|
+
const id = item[foreignKey];
|
|
693
|
+
if (id === null) {
|
|
694
|
+
row = void 0;
|
|
695
|
+
break;
|
|
696
|
+
} else {
|
|
697
|
+
(row ?? (row = [])).push(id);
|
|
698
|
+
}
|
|
698
699
|
}
|
|
700
|
+
if (row) ids.push(row);
|
|
699
701
|
}
|
|
700
|
-
|
|
702
|
+
}
|
|
703
|
+
if (!ids?.length) return;
|
|
704
|
+
const t = query.whereIn(
|
|
705
|
+
primaryKeys,
|
|
706
|
+
ids
|
|
707
|
+
);
|
|
708
|
+
if (params.delete) {
|
|
709
|
+
await _queryDelete(t);
|
|
710
|
+
} else {
|
|
711
|
+
await _queryUpdate(t, params.update);
|
|
701
712
|
}
|
|
702
713
|
}
|
|
703
|
-
|
|
704
|
-
const t = query.whereIn(
|
|
705
|
-
primaryKeys,
|
|
706
|
-
ids
|
|
707
|
-
);
|
|
708
|
-
if (params.delete) {
|
|
709
|
-
await _queryDelete(t);
|
|
710
|
-
} else {
|
|
711
|
-
await _queryUpdate(t, params.update);
|
|
712
|
-
}
|
|
713
|
-
});
|
|
714
|
+
);
|
|
714
715
|
}
|
|
715
716
|
};
|
|
716
717
|
};
|
|
@@ -2157,6 +2158,8 @@ const orchidORM = ({
|
|
|
2157
2158
|
Object.assign(result[key].baseQuery.q, table.q);
|
|
2158
2159
|
}
|
|
2159
2160
|
}
|
|
2161
|
+
const db = result;
|
|
2162
|
+
db.$adapter;
|
|
2160
2163
|
return result;
|
|
2161
2164
|
};
|
|
2162
2165
|
|