@mikro-orm/sql 7.2.9-dev.13 → 7.2.9-dev.15
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/AbstractSqlDriver.d.ts +5 -1
- package/AbstractSqlDriver.js +15 -19
- package/package.json +2 -2
- package/query/QueryBuilder.d.ts +0 -2
- package/query/QueryBuilder.js +1 -22
package/AbstractSqlDriver.d.ts
CHANGED
|
@@ -63,7 +63,11 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
63
63
|
private nativeCloneTPT;
|
|
64
64
|
private mapCloneOverrides;
|
|
65
65
|
private buildCloneFields;
|
|
66
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Returns properties whose columns can be copied by an `INSERT … SELECT` (owning columns that are not PKs, generated or formulas).
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
getCloneableProps<T extends object>(meta: EntityMetadata<T>, ownProps?: boolean): EntityProperty<T>[];
|
|
67
71
|
nativeInsertMany<T extends object>(entityName: EntityName<T>, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>;
|
|
68
72
|
/** Resolves the primary key of every inserted row from the supplied data or the returned rows, and reports them via `insertedIds` when all are known. */
|
|
69
73
|
protected resolveInsertedPrimaryKeys<T extends object>(meta: EntityMetadata<T>, data: EntityDictionary<T>[], res: QueryResult<T>): any[][];
|
package/AbstractSqlDriver.js
CHANGED
|
@@ -763,25 +763,12 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
763
763
|
}
|
|
764
764
|
return { selectFields, insertColumns };
|
|
765
765
|
}
|
|
766
|
+
/**
|
|
767
|
+
* Returns properties whose columns can be copied by an `INSERT … SELECT` (owning columns that are not PKs, generated or formulas).
|
|
768
|
+
* @internal
|
|
769
|
+
*/
|
|
766
770
|
getCloneableProps(meta, ownProps) {
|
|
767
|
-
return (ownProps ? (meta.ownProps ?? meta.props) : meta.props).filter(prop =>
|
|
768
|
-
if (prop.persist === false) {
|
|
769
|
-
return false;
|
|
770
|
-
}
|
|
771
|
-
if (prop.primary) {
|
|
772
|
-
return false;
|
|
773
|
-
}
|
|
774
|
-
if (!prop.fieldNames?.length) {
|
|
775
|
-
return false;
|
|
776
|
-
}
|
|
777
|
-
if ([ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {
|
|
778
|
-
return false;
|
|
779
|
-
}
|
|
780
|
-
if (prop.kind === ReferenceKind.EMBEDDED && !prop.object) {
|
|
781
|
-
return false;
|
|
782
|
-
}
|
|
783
|
-
return true;
|
|
784
|
-
});
|
|
771
|
+
return (ownProps ? (meta.ownProps ?? meta.props) : meta.props).filter(prop => !prop.primary && !prop.generated && this.platform.shouldHaveColumn(prop, true, undefined, false, false));
|
|
785
772
|
}
|
|
786
773
|
async nativeInsertMany(entityName, data, options = {}, transform) {
|
|
787
774
|
options.processCollections ??= true;
|
|
@@ -1130,6 +1117,7 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1130
1117
|
}
|
|
1131
1118
|
}
|
|
1132
1119
|
}
|
|
1120
|
+
const scalarColumn = prop.fieldNames.length > 1 && !prop.polymorphic ? this.getScalarFieldName(prop) : undefined;
|
|
1133
1121
|
prop.fieldNames.forEach((fieldName, fieldNameIdx) => {
|
|
1134
1122
|
if (fields.has(fieldName) || (prop.ownColumns && !prop.ownColumns.includes(fieldName))) {
|
|
1135
1123
|
return;
|
|
@@ -1151,7 +1139,15 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
1151
1139
|
sql += '?';
|
|
1152
1140
|
}
|
|
1153
1141
|
params.push(...pks);
|
|
1154
|
-
|
|
1142
|
+
const value = data[idx][key];
|
|
1143
|
+
const scalar = Array.isArray(value) && value.length === 1 ? value[0] : value;
|
|
1144
|
+
// a composite FK given as a scalar holds only the target PK, written to the column that references it
|
|
1145
|
+
if (scalarColumn && !isRaw(scalar) && Utils.isPrimaryKey(scalar)) {
|
|
1146
|
+
addParams(prop, (fieldName === scalarColumn ? scalar : null));
|
|
1147
|
+
}
|
|
1148
|
+
else {
|
|
1149
|
+
addParams(prop, prop.fieldNames.length > 1 ? value?.[fieldNameIdx] : value);
|
|
1150
|
+
}
|
|
1155
1151
|
}
|
|
1156
1152
|
});
|
|
1157
1153
|
sql += ` else ${this.platform.quoteIdentifier(fieldName)} end, `;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.9-dev.
|
|
3
|
+
"version": "7.2.9-dev.15",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"data-mapper",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@mikro-orm/core": "^7.2.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.9-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.9-dev.15"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -980,8 +980,6 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
980
980
|
* Tier 3: Derive from target entity metadata (all cloneable columns), auto-populate source select
|
|
981
981
|
*/
|
|
982
982
|
private resolveInsertFromColumns;
|
|
983
|
-
/** Returns properties that are safe to clone (persistable, non-PK, non-generated). */
|
|
984
|
-
private getCloneableProps;
|
|
985
983
|
private applyDiscriminatorCondition;
|
|
986
984
|
/**
|
|
987
985
|
* Ensures TPT joins are applied. Can be called early before finalize() to populate
|
package/query/QueryBuilder.js
CHANGED
|
@@ -1884,7 +1884,7 @@ export class QueryBuilder {
|
|
|
1884
1884
|
});
|
|
1885
1885
|
}
|
|
1886
1886
|
// Tier 3: derive from metadata — all cloneable columns
|
|
1887
|
-
const cloneableProps = this.getCloneableProps(meta);
|
|
1887
|
+
const cloneableProps = this.driver.getCloneableProps(meta);
|
|
1888
1888
|
const selectFields = [];
|
|
1889
1889
|
const columns = [];
|
|
1890
1890
|
for (const prop of cloneableProps) {
|
|
@@ -1899,27 +1899,6 @@ export class QueryBuilder {
|
|
|
1899
1899
|
}
|
|
1900
1900
|
return columns;
|
|
1901
1901
|
}
|
|
1902
|
-
/** Returns properties that are safe to clone (persistable, non-PK, non-generated). */
|
|
1903
|
-
getCloneableProps(meta) {
|
|
1904
|
-
return meta.props.filter(prop => {
|
|
1905
|
-
if (prop.persist === false) {
|
|
1906
|
-
return false;
|
|
1907
|
-
}
|
|
1908
|
-
if (prop.primary) {
|
|
1909
|
-
return false;
|
|
1910
|
-
}
|
|
1911
|
-
if (!prop.fieldNames?.length) {
|
|
1912
|
-
return false;
|
|
1913
|
-
}
|
|
1914
|
-
if ([ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {
|
|
1915
|
-
return false;
|
|
1916
|
-
}
|
|
1917
|
-
if (prop.kind === ReferenceKind.EMBEDDED && !prop.object) {
|
|
1918
|
-
return false;
|
|
1919
|
-
}
|
|
1920
|
-
return true;
|
|
1921
|
-
});
|
|
1922
|
-
}
|
|
1923
1902
|
applyDiscriminatorCondition() {
|
|
1924
1903
|
const meta = this.mainAlias.meta;
|
|
1925
1904
|
if (meta.root.inheritanceType !== 'sti' || !meta.discriminatorValue) {
|