@mikro-orm/knex 6.4.7-dev.2 → 6.4.7-dev.21
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.js
CHANGED
|
@@ -930,11 +930,11 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
930
930
|
getFieldsForJoinedLoad(qb, meta, explicitFields, exclude, populate = [], options, parentTableAlias, parentJoinPath, count) {
|
|
931
931
|
const fields = [];
|
|
932
932
|
const joinedProps = this.joinedProps(meta, populate, options);
|
|
933
|
-
const shouldHaveColumn = (prop, populate, fields) => {
|
|
933
|
+
const shouldHaveColumn = (meta, prop, populate, fields) => {
|
|
934
934
|
if (!this.platform.shouldHaveColumn(prop, populate, exclude)) {
|
|
935
935
|
return false;
|
|
936
936
|
}
|
|
937
|
-
if (!fields || fields.includes('*') || prop.primary) {
|
|
937
|
+
if (!fields || fields.includes('*') || prop.primary || meta.root.discriminatorColumn === prop.name) {
|
|
938
938
|
return true;
|
|
939
939
|
}
|
|
940
940
|
return fields.some(f => f === prop.name || f.toString().startsWith(prop.name + '.'));
|
|
@@ -944,7 +944,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
944
944
|
if (parentJoinPath) {
|
|
945
945
|
// alias all fields in the primary table
|
|
946
946
|
meta.props
|
|
947
|
-
.filter(prop => shouldHaveColumn(prop, populate, explicitFields))
|
|
947
|
+
.filter(prop => shouldHaveColumn(meta, prop, populate, explicitFields))
|
|
948
948
|
.forEach(prop => fields.push(...this.mapPropToFieldNames(qb, prop, parentTableAlias)));
|
|
949
949
|
}
|
|
950
950
|
for (const hint of joinedProps) {
|
|
@@ -1281,6 +1281,9 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
1281
1281
|
if (!options.fields.includes('*') && !options.fields.includes(`${qb.alias}.*`)) {
|
|
1282
1282
|
ret.unshift(...meta.primaryKeys.filter(pk => !options.fields.includes(pk)));
|
|
1283
1283
|
}
|
|
1284
|
+
if (meta.root.discriminatorColumn && !options.fields.includes(`${qb.alias}.${meta.root.discriminatorColumn}`)) {
|
|
1285
|
+
ret.push(meta.root.discriminatorColumn);
|
|
1286
|
+
}
|
|
1284
1287
|
}
|
|
1285
1288
|
else if (!core_1.Utils.isEmpty(options.exclude) || lazyProps.some(p => !p.formula && (p.kind !== '1:1' || p.owner))) {
|
|
1286
1289
|
const props = meta.props.filter(prop => this.platform.shouldHaveColumn(prop, populate, options.exclude, false));
|
|
@@ -59,12 +59,15 @@ class MsSqlQueryCompiler extends MonkeyPatchable_1.MonkeyPatchable.MsSqlQueryCom
|
|
|
59
59
|
|| (typeof insert === 'object' && core_1.Utils.isEmpty(insert));
|
|
60
60
|
}
|
|
61
61
|
_mergeOn(conflict) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
const conflictColumn = this.formatter.columnize(conflict[0]);
|
|
65
|
-
sql = `on ${this.tableName}.${conflictColumn} = tsource.${conflictColumn}`;
|
|
62
|
+
if (!Array.isArray(conflict)) {
|
|
63
|
+
return 'on 1=1';
|
|
66
64
|
}
|
|
67
|
-
|
|
65
|
+
const parts = [];
|
|
66
|
+
for (const col of conflict) {
|
|
67
|
+
const conflictColumn = this.formatter.columnize(col);
|
|
68
|
+
parts.push(`${this.tableName}.${conflictColumn} = tsource.${conflictColumn}`);
|
|
69
|
+
}
|
|
70
|
+
return `on ${parts.join(' and ')}`;
|
|
68
71
|
}
|
|
69
72
|
_insertWithMerge() {
|
|
70
73
|
const { insert = [], onConflict, ignore, merge, returning, options = {} } = this.single;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.4.7-dev.
|
|
3
|
+
"version": "6.4.7-dev.21",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.4.6"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.4.7-dev.
|
|
69
|
+
"@mikro-orm/core": "6.4.7-dev.21",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
package/query/CriteriaNode.js
CHANGED
|
@@ -72,16 +72,12 @@ class CriteriaNode {
|
|
|
72
72
|
let joinAlias = qb.getAliasForJoinPath(this.getPath());
|
|
73
73
|
if (!joinAlias && this.parent && [core_1.ReferenceKind.MANY_TO_ONE, core_1.ReferenceKind.ONE_TO_ONE].includes(this.prop.kind) && this.prop.owner) {
|
|
74
74
|
joinAlias = qb.getAliasForJoinPath(this.parent.getPath());
|
|
75
|
-
return core_1.Utils.getPrimaryKeyHash(this.prop.
|
|
75
|
+
return core_1.Utils.getPrimaryKeyHash(this.prop.ownColumns.map(col => `${joinAlias ?? qb.alias}.${col}`));
|
|
76
76
|
}
|
|
77
77
|
const alias = joinAlias ?? qb.alias;
|
|
78
78
|
if (this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY) {
|
|
79
79
|
return core_1.Utils.getPrimaryKeyHash(this.prop.inverseJoinColumns.map(col => `${alias}.${col}`));
|
|
80
80
|
}
|
|
81
|
-
// if we found a matching join, we need to use the target table column names, as we use that alias instead of the root
|
|
82
|
-
if (!joinAlias && this.prop.owner && this.prop.joinColumns.length > 1) {
|
|
83
|
-
return core_1.Utils.getPrimaryKeyHash(this.prop.joinColumns.map(col => `${alias}.${col}`));
|
|
84
|
-
}
|
|
85
81
|
return core_1.Utils.getPrimaryKeyHash(this.prop.referencedColumnNames.map(col => `${alias}.${col}`));
|
|
86
82
|
}
|
|
87
83
|
getPath(addIndex = false) {
|
|
@@ -43,9 +43,6 @@ class QueryBuilderHelper {
|
|
|
43
43
|
const prop = this.getProperty(f, a);
|
|
44
44
|
const fkIdx2 = prop?.fieldNames.findIndex(name => name === f) ?? -1;
|
|
45
45
|
if (fkIdx2 !== -1) {
|
|
46
|
-
if (prop?.ownColumns && !prop.ownColumns.includes(f)) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
46
|
parts.push(this.mapper(a !== this.alias ? `${a}.${prop.fieldNames[fkIdx2]}` : prop.fieldNames[fkIdx2], type, value, alias));
|
|
50
47
|
}
|
|
51
48
|
else if (prop) {
|
|
@@ -66,9 +63,6 @@ class QueryBuilderHelper {
|
|
|
66
63
|
}
|
|
67
64
|
});
|
|
68
65
|
}
|
|
69
|
-
if (parts.length === 1) {
|
|
70
|
-
return parts[0];
|
|
71
|
-
}
|
|
72
66
|
return this.knex.raw('(' + parts.map(part => this.knex.ref(part)).join(', ') + ')');
|
|
73
67
|
}
|
|
74
68
|
const rawField = core_1.RawQueryFragment.getKnownFragment(field);
|
|
@@ -103,9 +103,10 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
103
103
|
return super.clearDatabase(options);
|
|
104
104
|
}
|
|
105
105
|
await this.execute(this.helper.disableForeignKeysSQL());
|
|
106
|
-
|
|
106
|
+
const schema = options?.schema ?? this.config.get('schema', this.platform.getDefaultSchemaName());
|
|
107
|
+
for (const meta of this.getOrderedMetadata(schema).reverse()) {
|
|
107
108
|
await this.driver.createQueryBuilder(meta.className, this.em?.getTransactionContext(), 'write', false)
|
|
108
|
-
.withSchema(
|
|
109
|
+
.withSchema(schema)
|
|
109
110
|
.truncate();
|
|
110
111
|
}
|
|
111
112
|
await this.execute(this.helper.enableForeignKeysSQL());
|