@mikro-orm/core 7.2.0-dev.8 → 7.2.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/EntityManager.d.ts +41 -7
- package/EntityManager.js +225 -45
- package/MikroORM.d.ts +4 -0
- package/MikroORM.js +9 -0
- package/README.md +1 -0
- package/connections/Connection.d.ts +3 -1
- package/drivers/DatabaseDriver.d.ts +14 -5
- package/drivers/DatabaseDriver.js +151 -52
- package/drivers/IDatabaseDriver.d.ts +1 -0
- package/entity/Collection.js +4 -2
- package/entity/EntityFactory.js +6 -0
- package/entity/EntityLoader.d.ts +7 -1
- package/entity/EntityLoader.js +46 -11
- package/entity/EntityRepository.d.ts +4 -5
- package/entity/EntityRepository.js +7 -2
- package/entity/defineEntity.d.ts +48 -14
- package/entity/defineEntity.js +32 -1
- package/enums.d.ts +5 -1
- package/enums.js +2 -0
- package/errors.d.ts +36 -0
- package/errors.js +90 -0
- package/events/EventManager.js +6 -3
- package/exceptions.d.ts +5 -0
- package/exceptions.js +5 -0
- package/hydration/ObjectHydrator.d.ts +2 -0
- package/hydration/ObjectHydrator.js +12 -8
- package/index.d.ts +1 -1
- package/metadata/MetadataDiscovery.d.ts +3 -0
- package/metadata/MetadataDiscovery.js +133 -18
- package/metadata/MetadataStorage.js +17 -1
- package/metadata/types.d.ts +19 -3
- package/package.json +1 -1
- package/platforms/Platform.d.ts +22 -3
- package/platforms/Platform.js +59 -1
- package/types/BigIntType.d.ts +1 -0
- package/types/BigIntType.js +23 -0
- package/types/DateTimeType.d.ts +1 -0
- package/types/DateTimeType.js +8 -0
- package/types/StringType.d.ts +14 -3
- package/types/StringType.js +34 -4
- package/types/TextType.d.ts +2 -4
- package/types/TextType.js +2 -8
- package/types/Type.d.ts +11 -0
- package/types/Type.js +4 -4
- package/types/index.d.ts +2 -2
- package/typings.d.ts +56 -2
- package/typings.js +24 -1
- package/unit-of-work/ChangeSetPersister.js +17 -13
- package/unit-of-work/UnitOfWork.js +11 -4
- package/utils/Configuration.d.ts +15 -1
- package/utils/Configuration.js +11 -1
- package/utils/Cursor.d.ts +2 -0
- package/utils/Cursor.js +43 -33
- package/utils/DataloaderUtils.js +2 -1
- package/utils/EntityComparator.d.ts +2 -0
- package/utils/EntityComparator.js +7 -3
- package/utils/QueryHelper.d.ts +12 -0
- package/utils/QueryHelper.js +75 -4
- package/utils/RawQueryFragment.d.ts +6 -0
- package/utils/RawQueryFragment.js +15 -6
- package/utils/TransactionManager.js +1 -1
- package/utils/Utils.d.ts +14 -2
- package/utils/Utils.js +31 -4
- package/utils/env-vars.js +1 -0
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/rls-utils.d.ts +35 -0
- package/utils/rls-utils.js +97 -0
- package/utils/upsert-utils.d.ts +9 -1
- package/utils/upsert-utils.js +26 -3
package/utils/upsert-utils.js
CHANGED
|
@@ -72,6 +72,22 @@ export function getOnConflictFields(meta, data, uniqueFields, options) {
|
|
|
72
72
|
}
|
|
73
73
|
return keys;
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Detects properties that will get their value generated by an `onCreate` hook during the upsert,
|
|
77
|
+
* i.e. those with an `onCreate` hook and no value provided. Such values are meant for the insert
|
|
78
|
+
* clause only and must not overwrite an existing row via the `on conflict do update set` clause.
|
|
79
|
+
* The property filter mirrors `EntityFactory.assignDefaultValues`.
|
|
80
|
+
* @internal
|
|
81
|
+
*/
|
|
82
|
+
export function getOnCreateGeneratedFields(meta, data) {
|
|
83
|
+
return meta.props
|
|
84
|
+
.filter(prop => prop.onCreate &&
|
|
85
|
+
!prop.embedded &&
|
|
86
|
+
![ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) &&
|
|
87
|
+
!(prop.getter && !prop.setter) &&
|
|
88
|
+
data[prop.name] == null)
|
|
89
|
+
.map(prop => prop.name);
|
|
90
|
+
}
|
|
75
91
|
/** @internal */
|
|
76
92
|
export function getOnConflictReturningFields(meta, data, uniqueFields, options) {
|
|
77
93
|
/* v8 ignore next */
|
|
@@ -122,7 +138,14 @@ function getPropertyValue(obj, key) {
|
|
|
122
138
|
}
|
|
123
139
|
/** @internal */
|
|
124
140
|
export function getWhereCondition(meta, onConflictFields, data, where) {
|
|
125
|
-
|
|
141
|
+
// TPT children do not inherit the unique flags and indexes of their parent tables
|
|
142
|
+
const uniqueProps = new Set();
|
|
143
|
+
const uniques = [];
|
|
144
|
+
for (let current = meta; current; current = current.tptParent) {
|
|
145
|
+
current.props.filter(p => p.unique).forEach(p => uniqueProps.add(p.name));
|
|
146
|
+
uniques.push(...current.uniques);
|
|
147
|
+
}
|
|
148
|
+
const unique = onConflictFields ?? [...uniqueProps];
|
|
126
149
|
const propIndex = !isRaw(unique) &&
|
|
127
150
|
unique.findIndex(p => data[p] ?? data[p.substring(0, p.indexOf('.'))] != null);
|
|
128
151
|
if (onConflictFields || where == null) {
|
|
@@ -136,8 +159,8 @@ export function getWhereCondition(meta, onConflictFields, data, where) {
|
|
|
136
159
|
}
|
|
137
160
|
where = { [key]: getPropertyValue(data, unique[propIndex]) };
|
|
138
161
|
}
|
|
139
|
-
else
|
|
140
|
-
for (const u of
|
|
162
|
+
else {
|
|
163
|
+
for (const u of uniques) {
|
|
141
164
|
if (Utils.asArray(u.properties).every(p => data[p] != null)) {
|
|
142
165
|
where = Utils.asArray(u.properties).reduce((o, key) => {
|
|
143
166
|
o[key] = data[key];
|