@mikro-orm/knex 6.1.10-dev.8 → 6.1.10
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
|
@@ -826,7 +826,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
826
826
|
if (!item[propName]) {
|
|
827
827
|
continue;
|
|
828
828
|
}
|
|
829
|
-
if (
|
|
829
|
+
if ([core_1.ReferenceKind.ONE_TO_MANY, core_1.ReferenceKind.MANY_TO_MANY].includes(prop.kind) && ref) {
|
|
830
830
|
map[pk][propName] = [...map[pk][propName], ...item[propName]];
|
|
831
831
|
continue;
|
|
832
832
|
}
|
|
@@ -922,28 +922,31 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
922
922
|
* @internal
|
|
923
923
|
*/
|
|
924
924
|
mapPropToFieldNames(qb, prop, tableAlias) {
|
|
925
|
-
const
|
|
926
|
-
const aliased = knex.ref(tableAlias ? `${tableAlias}__${prop.fieldNames[0]}` : prop.fieldNames[0]).toString();
|
|
925
|
+
const aliased = this.platform.quoteIdentifier(tableAlias ? `${tableAlias}__${prop.fieldNames[0]}` : prop.fieldNames[0]);
|
|
927
926
|
if (tableAlias && prop.customTypes?.some(type => type?.convertToJSValueSQL)) {
|
|
928
927
|
return prop.fieldNames.map((col, idx) => {
|
|
929
928
|
if (!prop.customTypes[idx]?.convertToJSValueSQL) {
|
|
930
929
|
return col;
|
|
931
930
|
}
|
|
932
|
-
const prefixed =
|
|
933
|
-
const aliased =
|
|
931
|
+
const prefixed = this.platform.quoteIdentifier(`${tableAlias}.${col}`);
|
|
932
|
+
const aliased = this.platform.quoteIdentifier(`${tableAlias}__${col}`);
|
|
934
933
|
return (0, core_1.raw)(`${prop.customTypes[idx].convertToJSValueSQL(prefixed, this.platform)} as ${aliased}`);
|
|
935
934
|
});
|
|
936
935
|
}
|
|
937
936
|
if (tableAlias && prop.customType?.convertToJSValueSQL) {
|
|
938
|
-
const prefixed =
|
|
937
|
+
const prefixed = this.platform.quoteIdentifier(`${tableAlias}.${prop.fieldNames[0]}`);
|
|
939
938
|
return [(0, core_1.raw)(`${prop.customType.convertToJSValueSQL(prefixed, this.platform)} as ${aliased}`)];
|
|
940
939
|
}
|
|
941
940
|
if (prop.formula) {
|
|
942
|
-
const alias =
|
|
941
|
+
const alias = this.platform.quoteIdentifier(tableAlias ?? qb.alias);
|
|
943
942
|
return [(0, core_1.raw)(`${prop.formula(alias)} as ${aliased}`)];
|
|
944
943
|
}
|
|
945
944
|
if (tableAlias) {
|
|
946
|
-
return prop.fieldNames.map(fieldName =>
|
|
945
|
+
return prop.fieldNames.map(fieldName => {
|
|
946
|
+
const name = this.platform.quoteIdentifier(`${tableAlias}.${fieldName}`);
|
|
947
|
+
const alias = this.platform.quoteIdentifier(`${tableAlias}__${fieldName}`);
|
|
948
|
+
return (0, core_1.raw)(`${name} as ${alias}`);
|
|
949
|
+
});
|
|
947
950
|
}
|
|
948
951
|
return prop.fieldNames;
|
|
949
952
|
}
|
|
@@ -1207,8 +1210,8 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
1207
1210
|
meta.props
|
|
1208
1211
|
.filter(prop => prop.formula && !lazyProps.includes(prop))
|
|
1209
1212
|
.forEach(prop => {
|
|
1210
|
-
const a = this.
|
|
1211
|
-
const aliased = this.
|
|
1213
|
+
const a = this.platform.quoteIdentifier(alias);
|
|
1214
|
+
const aliased = this.platform.quoteIdentifier(prop.fieldNames[0]);
|
|
1212
1215
|
ret.push((0, core_1.raw)(`${prop.formula(a)} as ${aliased}`));
|
|
1213
1216
|
});
|
|
1214
1217
|
meta.props
|
package/AbstractSqlPlatform.js
CHANGED
|
@@ -55,8 +55,11 @@ class AbstractSqlPlatform extends core_1.Platform {
|
|
|
55
55
|
getJsonIndexDefinition(index) {
|
|
56
56
|
return index.columnNames
|
|
57
57
|
.map(column => {
|
|
58
|
+
if (!column.includes('.')) {
|
|
59
|
+
return column;
|
|
60
|
+
}
|
|
58
61
|
const [root, ...path] = column.split('.');
|
|
59
|
-
return `json_extract(${root}, '$.${path.join('.')}')`;
|
|
62
|
+
return `(json_extract(${root}, '$.${path.join('.')}'))`;
|
|
60
63
|
});
|
|
61
64
|
}
|
|
62
65
|
isRaw(value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.1.10
|
|
3
|
+
"version": "6.1.10",
|
|
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",
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"sqlstring": "2.3.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@mikro-orm/core": "^6.1.
|
|
66
|
+
"@mikro-orm/core": "^6.1.10"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.
|
|
69
|
+
"@mikro-orm/core": "^6.0.0"
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -86,7 +86,11 @@ class QueryBuilderHelper {
|
|
|
86
86
|
const alias2 = this.knex.ref(a).toString();
|
|
87
87
|
const aliased = this.knex.ref(prop.fieldNames[0]).toString();
|
|
88
88
|
const as = alias === null ? '' : ` as ${aliased}`;
|
|
89
|
-
|
|
89
|
+
let value = prop.formula(alias2);
|
|
90
|
+
if (!this.isTableNameAliasRequired(type)) {
|
|
91
|
+
value = value.replaceAll(alias2 + '.', '');
|
|
92
|
+
}
|
|
93
|
+
return this.knex.raw(`${value}${as}`);
|
|
90
94
|
}
|
|
91
95
|
if (prop?.hasConvertToJSValueSQL) {
|
|
92
96
|
let valueSQL;
|
|
@@ -498,7 +498,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
498
498
|
// JSON columns can have unique index but not unique constraint, and we need to distinguish those, so we can properly drop them
|
|
499
499
|
if (index.columnNames.some(column => column.includes('.'))) {
|
|
500
500
|
const columns = this.platform.getJsonIndexDefinition(index);
|
|
501
|
-
table.index(columns.map(column => this.knex.raw(
|
|
501
|
+
table.index(columns.map(column => this.knex.raw(column)), index.keyName, { indexType: 'unique' });
|
|
502
502
|
}
|
|
503
503
|
else {
|
|
504
504
|
table.unique(index.columnNames, { indexName: index.keyName });
|
|
@@ -517,7 +517,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
517
517
|
// JSON columns can have unique index but not unique constraint, and we need to distinguish those, so we can properly drop them
|
|
518
518
|
if (index.columnNames.some(column => column.includes('.'))) {
|
|
519
519
|
const columns = this.platform.getJsonIndexDefinition(index);
|
|
520
|
-
table.index(columns.map(column => this.knex.raw(
|
|
520
|
+
table.index(columns.map(column => this.knex.raw(column)), index.keyName, index.type);
|
|
521
521
|
}
|
|
522
522
|
else {
|
|
523
523
|
table.index(index.columnNames, index.keyName, index.type);
|