@mikro-orm/sql 7.1.11-dev.4 → 7.1.11-dev.5
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/package.json +2 -2
- package/schema/DatabaseTable.js +21 -8
- package/typings.d.ts +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.1.11-dev.
|
|
3
|
+
"version": "7.1.11-dev.5",
|
|
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.1.10"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.11-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.11-dev.5"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -219,6 +219,7 @@ export class DatabaseTable {
|
|
|
219
219
|
skippedColumnNames.includes(index.columnNames[0]) || // Non-composite indexes for skipped columns are to be mapped as entity decorators.
|
|
220
220
|
index.deferMode ||
|
|
221
221
|
index.expression ||
|
|
222
|
+
index.where ||
|
|
222
223
|
!(index.columnNames[0] in columnFks)) && // Trivial non-composite indexes for scalar props are to be mapped to the column.
|
|
223
224
|
// ignore indexes that don't have all column names (this can happen in sqlite where there is no way to infer this for expressions)
|
|
224
225
|
!(index.columnNames.some(col => !col) && !index.expression));
|
|
@@ -507,7 +508,8 @@ export class DatabaseTable {
|
|
|
507
508
|
findFkIndex(currentFk) {
|
|
508
509
|
const fkColumnsLength = currentFk.columnNames.length;
|
|
509
510
|
const possibleIndexes = this.#indexes.filter(index => {
|
|
510
|
-
return (index.
|
|
511
|
+
return (!index.where &&
|
|
512
|
+
index.columnNames.length === fkColumnsLength &&
|
|
511
513
|
!currentFk.columnNames.some((columnName, i) => index.columnNames[i] !== columnName));
|
|
512
514
|
});
|
|
513
515
|
possibleIndexes.sort((a, b) => {
|
|
@@ -522,12 +524,20 @@ export class DatabaseTable {
|
|
|
522
524
|
return possibleIndexes.at(0);
|
|
523
525
|
}
|
|
524
526
|
getIndexProperties(index, columnFks, fksOnColumnProps, fksOnStandaloneProps, namingStrategy) {
|
|
525
|
-
const propBaseNames = new
|
|
527
|
+
const propBaseNames = new Map();
|
|
526
528
|
const columnNames = index.columnNames;
|
|
527
529
|
const l = columnNames.length;
|
|
528
530
|
if (columnNames.some(col => !col)) {
|
|
529
531
|
return;
|
|
530
532
|
}
|
|
533
|
+
const addPropBaseName = (baseName, position) => {
|
|
534
|
+
const positions = propBaseNames.get(baseName);
|
|
535
|
+
if (positions) {
|
|
536
|
+
positions.last = position;
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
propBaseNames.set(baseName, { first: position, last: position });
|
|
540
|
+
};
|
|
531
541
|
for (let i = 0; i < l; ++i) {
|
|
532
542
|
const columnName = columnNames[i];
|
|
533
543
|
// The column is not involved with FKs.
|
|
@@ -538,14 +548,14 @@ export class DatabaseTable {
|
|
|
538
548
|
}
|
|
539
549
|
// It has a prop named after it.
|
|
540
550
|
// Add it and move on.
|
|
541
|
-
|
|
551
|
+
addPropBaseName(columnName, i);
|
|
542
552
|
continue;
|
|
543
553
|
}
|
|
544
554
|
// If the prop named after the column has a FK and the FK's columns are a subset of this index,
|
|
545
555
|
// include this prop and move on.
|
|
546
556
|
const columnPropFk = fksOnColumnProps.get(columnName);
|
|
547
557
|
if (columnPropFk && !columnPropFk.columnNames.some(fkColumnName => !columnNames.includes(fkColumnName))) {
|
|
548
|
-
|
|
558
|
+
addPropBaseName(columnName, i);
|
|
549
559
|
continue;
|
|
550
560
|
}
|
|
551
561
|
// If there is at least one standalone FK featuring this column,
|
|
@@ -557,7 +567,7 @@ export class DatabaseTable {
|
|
|
557
567
|
continue;
|
|
558
568
|
}
|
|
559
569
|
if (!fk.columnNames.some(fkColumnName => !columnNames.includes(fkColumnName))) {
|
|
560
|
-
|
|
570
|
+
addPropBaseName(propName, i);
|
|
561
571
|
propAdded = true;
|
|
562
572
|
}
|
|
563
573
|
}
|
|
@@ -568,7 +578,10 @@ export class DatabaseTable {
|
|
|
568
578
|
// Break the whole prop creation.
|
|
569
579
|
return;
|
|
570
580
|
}
|
|
571
|
-
|
|
581
|
+
// Props sharing their first column would otherwise follow FK discovery order, so break ties on the last one.
|
|
582
|
+
return Array.from(propBaseNames)
|
|
583
|
+
.sort(([, a], [, b]) => a.first - b.first || a.last - b.last)
|
|
584
|
+
.map(([baseName]) => this.getPropertyName(namingStrategy, baseName, fksOnColumnProps.get(baseName)));
|
|
572
585
|
}
|
|
573
586
|
getSafeBaseNameForFkProp(namingStrategy, currentFk, fks, columnName) {
|
|
574
587
|
if (columnName &&
|
|
@@ -694,9 +707,9 @@ export class DatabaseTable {
|
|
|
694
707
|
const prop = this.getPropertyName(namingStrategy, column.name, fk);
|
|
695
708
|
const persist = !(column.name in columnFks && typeof fk === 'undefined');
|
|
696
709
|
const index = compositeFkIndexes[prop] ||
|
|
697
|
-
this.#indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && !idx.unique && !idx.primary);
|
|
710
|
+
this.#indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && !idx.unique && !idx.primary && !idx.where);
|
|
698
711
|
const unique = compositeFkUniques[prop] ||
|
|
699
|
-
this.#indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && idx.unique && !idx.primary);
|
|
712
|
+
this.#indexes.find(idx => idx.columnNames[0] === column.name && !idx.composite && idx.unique && !idx.primary && !idx.where);
|
|
700
713
|
const kind = this.getReferenceKind(fk, unique);
|
|
701
714
|
const runtimeType = this.getPropertyTypeForColumn(namingStrategy, column, fk);
|
|
702
715
|
const type = fk
|
package/typings.d.ts
CHANGED
|
@@ -368,9 +368,9 @@ type MaybeGenerated<TValue, TOptions, TProcessOnCreate extends boolean> = TOptio
|
|
|
368
368
|
} ? TValue | null : TOptions extends {
|
|
369
369
|
autoincrement: true;
|
|
370
370
|
} ? Generated<TValue> : TOptions extends {
|
|
371
|
-
default:
|
|
371
|
+
default: unknown;
|
|
372
372
|
} ? Generated<TValue> : TOptions extends {
|
|
373
|
-
defaultRaw:
|
|
373
|
+
defaultRaw: unknown;
|
|
374
374
|
} ? Generated<TValue> : TProcessOnCreate extends false ? TValue : TOptions extends {
|
|
375
375
|
onCreate: Function;
|
|
376
376
|
} ? Generated<TValue> : TValue;
|