@mikro-orm/knex 5.9.5-dev.1 → 5.9.5-dev.3
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
|
@@ -81,7 +81,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
81
81
|
if (typeof meta.expression === 'string') {
|
|
82
82
|
return this.wrapVirtualExpressionInSubquery(meta, meta.expression, where, options, type);
|
|
83
83
|
}
|
|
84
|
-
const em = this.createEntityManager(
|
|
84
|
+
const em = this.createEntityManager();
|
|
85
85
|
em.setTransactionContext(options.ctx);
|
|
86
86
|
const res = meta.expression(em, where, options);
|
|
87
87
|
if (typeof res === 'string') {
|
|
@@ -173,19 +173,21 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
173
173
|
relationPojo[prop.name] = root[alias];
|
|
174
174
|
}
|
|
175
175
|
});
|
|
176
|
-
meta2.props
|
|
177
|
-
|
|
178
|
-
.forEach(prop => {
|
|
176
|
+
const props = meta2.props.filter(prop => this.platform.shouldHaveColumn(prop, p.children || []));
|
|
177
|
+
for (const prop of props) {
|
|
179
178
|
if (prop.fieldNames.length > 1) { // composite keys
|
|
180
179
|
relationPojo[prop.name] = prop.fieldNames.map(name => root[`${relationAlias}__${name}`]);
|
|
181
|
-
prop.fieldNames.map(name => delete root[`${relationAlias}__${name}`]);
|
|
182
180
|
}
|
|
183
181
|
else {
|
|
184
182
|
const alias = `${relationAlias}__${prop.fieldNames[0]}`;
|
|
185
183
|
relationPojo[prop.name] = root[alias];
|
|
186
|
-
delete root[alias];
|
|
187
184
|
}
|
|
188
|
-
}
|
|
185
|
+
}
|
|
186
|
+
// properties can be mapped to multiple places, e.g. when sharing a column in multiple FKs,
|
|
187
|
+
// so we need to delete them after everything is mapped from given level
|
|
188
|
+
for (const prop of props) {
|
|
189
|
+
prop.fieldNames.map(name => delete root[`${relationAlias}__${name}`]);
|
|
190
|
+
}
|
|
189
191
|
if ([core_1.ReferenceType.MANY_TO_MANY, core_1.ReferenceType.ONE_TO_MANY].includes(relation.reference)) {
|
|
190
192
|
result[relation.name] = result[relation.name] || [];
|
|
191
193
|
result[relation.name].push(relationPojo);
|
|
@@ -374,6 +376,7 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
374
376
|
}
|
|
375
377
|
const collections = options.processCollections ? data.map(d => this.extractManyToMany(entityName, d)) : [];
|
|
376
378
|
const keys = new Set();
|
|
379
|
+
const fields = new Set();
|
|
377
380
|
data.forEach(row => Object.keys(row).forEach(k => keys.add(k)));
|
|
378
381
|
const pkCond = core_1.Utils.flatten(meta.primaryKeys.map(pk => meta.properties[pk].fieldNames)).map(pk => `${this.platform.quoteIdentifier(pk)} = ?`).join(' and ');
|
|
379
382
|
const params = [];
|
|
@@ -381,6 +384,10 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
381
384
|
keys.forEach(key => {
|
|
382
385
|
const prop = meta.properties[key];
|
|
383
386
|
prop.fieldNames.forEach((fieldName, fieldNameIdx) => {
|
|
387
|
+
if (fields.has(fieldName)) {
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
fields.add(fieldName);
|
|
384
391
|
sql += `${this.platform.quoteIdentifier(fieldName)} = case`;
|
|
385
392
|
where.forEach((cond, idx) => {
|
|
386
393
|
if (key in data[idx]) {
|
package/AbstractSqlPlatform.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ export declare abstract class AbstractSqlPlatform extends Platform {
|
|
|
14
14
|
quoteValue(value: any): string;
|
|
15
15
|
formatQuery(sql: string, params: readonly any[]): string;
|
|
16
16
|
getSearchJsonPropertySQL(path: string, type: string, aliased: boolean): string;
|
|
17
|
-
getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean): string;
|
|
17
|
+
getSearchJsonPropertyKey(path: string[], type: string, aliased: boolean, value?: unknown): string;
|
|
18
18
|
isRaw(value: any): boolean;
|
|
19
19
|
supportsSchemas(): boolean;
|
|
20
20
|
/** @inheritDoc */
|
package/AbstractSqlPlatform.js
CHANGED
|
@@ -82,7 +82,7 @@ class AbstractSqlPlatform extends core_1.Platform {
|
|
|
82
82
|
getSearchJsonPropertySQL(path, type, aliased) {
|
|
83
83
|
return this.getSearchJsonPropertyKey(path.split('->'), type, aliased);
|
|
84
84
|
}
|
|
85
|
-
getSearchJsonPropertyKey(path, type, aliased) {
|
|
85
|
+
getSearchJsonPropertyKey(path, type, aliased, value) {
|
|
86
86
|
const [a, ...b] = path;
|
|
87
87
|
const quoteKey = (key) => key.match(/^[a-z]\w*$/i) ? key : `"${key}"`;
|
|
88
88
|
if (aliased) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "5.9.5-dev.
|
|
3
|
+
"version": "5.9.5-dev.3",
|
|
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,9 +66,9 @@
|
|
|
66
66
|
"@mikro-orm/core": "^5.9.4"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "5.9.5-dev.
|
|
70
|
-
"@mikro-orm/entity-generator": "5.9.5-dev.
|
|
71
|
-
"@mikro-orm/migrations": "5.9.5-dev.
|
|
69
|
+
"@mikro-orm/core": "5.9.5-dev.3",
|
|
70
|
+
"@mikro-orm/entity-generator": "5.9.5-dev.3",
|
|
71
|
+
"@mikro-orm/migrations": "5.9.5-dev.3",
|
|
72
72
|
"better-sqlite3": "*",
|
|
73
73
|
"mssql": "*",
|
|
74
74
|
"mysql": "*",
|
|
@@ -20,6 +20,12 @@ class ScalarCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
20
20
|
qb.addSelect(field);
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
if (this.payload && typeof this.payload === 'object') {
|
|
24
|
+
const keys = Object.keys(this.payload).filter(key => core_1.Utils.isArrayOperator(key) && Array.isArray(this.payload[key]));
|
|
25
|
+
for (const key of keys) {
|
|
26
|
+
this.payload[key] = JSON.stringify(this.payload[key]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
23
29
|
return this.payload;
|
|
24
30
|
}
|
|
25
31
|
willAutoJoin(qb, alias) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type Dictionary } from '@mikro-orm/core';
|
|
1
2
|
import type { Check, Column, ForeignKey, Index, SchemaDifference, TableDifference } from '../typings';
|
|
2
3
|
import type { DatabaseSchema } from './DatabaseSchema';
|
|
3
4
|
import type { DatabaseTable } from './DatabaseTable';
|
|
@@ -51,6 +52,7 @@ export declare class SchemaComparator {
|
|
|
51
52
|
*/
|
|
52
53
|
isIndexFulfilledBy(index1: Index, index2: Index): boolean;
|
|
53
54
|
diffCheck(check1: Check, check2: Check): boolean;
|
|
55
|
+
parseJsonDefault(defaultValue?: string | null): Dictionary | string | null;
|
|
54
56
|
hasSameDefaultValue(from: Column, to: Column): boolean;
|
|
55
57
|
private mapColumnToProperty;
|
|
56
58
|
private log;
|
|
@@ -436,6 +436,15 @@ class SchemaComparator {
|
|
|
436
436
|
const simplify = (str) => str?.replace(/['"`()]/g, '').toLowerCase();
|
|
437
437
|
return simplify(check1.expression) !== simplify(check2.expression);
|
|
438
438
|
}
|
|
439
|
+
parseJsonDefault(defaultValue) {
|
|
440
|
+
if (!defaultValue) {
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
const val = defaultValue
|
|
444
|
+
.replace(/^(_\w+\\)?'(.*?)\\?'$/, '$2')
|
|
445
|
+
.replace(/^\(?'(.*?)'\)?$/, '$1');
|
|
446
|
+
return (0, core_1.parseJsonSafe)(val);
|
|
447
|
+
}
|
|
439
448
|
hasSameDefaultValue(from, to) {
|
|
440
449
|
if (from.default == null || from.default.toString().toLowerCase() === 'null' || from.default.toString().startsWith('nextval(')) {
|
|
441
450
|
return to.default == null || to.default.toLowerCase() === 'null';
|
|
@@ -446,8 +455,8 @@ class SchemaComparator {
|
|
|
446
455
|
return defaultValueFrom === defaultValueTo;
|
|
447
456
|
}
|
|
448
457
|
if (to.mappedType instanceof core_1.JsonType) {
|
|
449
|
-
const defaultValueFrom =
|
|
450
|
-
const defaultValueTo =
|
|
458
|
+
const defaultValueFrom = this.parseJsonDefault(from.default);
|
|
459
|
+
const defaultValueTo = this.parseJsonDefault(to.default);
|
|
451
460
|
return core_1.Utils.equals(defaultValueFrom, defaultValueTo);
|
|
452
461
|
}
|
|
453
462
|
if (to.mappedType instanceof core_1.DateTimeType && from.default && to.default) {
|