@mikro-orm/sql 7.2.10-dev.2 → 7.2.10-dev.20
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ALIAS_REPLACEMENT_RE, DatabaseDriver, EntityManagerType, getLoadingStrategy, getOnConflictFields, getOnConflictReturningFields, helper, isRaw, LoadStrategy, parseJsonSafe, PolymorphicRef, QueryFlag, QueryHelper, QueryOrder, raw, RawQueryFragment, ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
1
|
+
import { ALIAS_REPLACEMENT_RE, DatabaseDriver, DateType, EntityManagerType, getLoadingStrategy, getOnConflictFields, getOnConflictReturningFields, helper, isRaw, LoadStrategy, parseJsonSafe, PolymorphicRef, QueryFlag, QueryHelper, QueryOrder, raw, RawQueryFragment, ReferenceKind, Utils, } from '@mikro-orm/core';
|
|
2
2
|
import { QueryBuilder } from './query/QueryBuilder.js';
|
|
3
3
|
import { JoinType, QueryType } from './query/enums.js';
|
|
4
4
|
import { SqlEntityManager } from './SqlEntityManager.js';
|
|
@@ -612,6 +612,11 @@ export class AbstractSqlDriver extends DatabaseDriver {
|
|
|
612
612
|
relationPojo[prop.name] = value;
|
|
613
613
|
}
|
|
614
614
|
}
|
|
615
|
+
else if (prop.customType instanceof DateType) {
|
|
616
|
+
// tedious returns DATE columns as `Date`, map them to the string the entity holds, so the snapshot matches it
|
|
617
|
+
const value = row[keys[0]];
|
|
618
|
+
relationPojo[prop.name] = (value instanceof Date ? this.platform.convertDateToJSValue(value) : value);
|
|
619
|
+
}
|
|
615
620
|
else {
|
|
616
621
|
relationPojo[prop.name] = row[keys[0]];
|
|
617
622
|
if (prop.kind === ReferenceKind.EMBEDDED && (prop.object || meta.embeddable)) {
|
|
@@ -1279,9 +1279,11 @@ export class PostgreSqlSchemaHelper extends SchemaHelper {
|
|
|
1279
1279
|
const name = (schemaName && schemaName !== this.platform.getDefaultSchemaName() ? schemaName + '.' : '') + tableName;
|
|
1280
1280
|
if (column.autoincrement) {
|
|
1281
1281
|
const seqName = this.platform.getIndexName(tableName, [column.name], 'sequence');
|
|
1282
|
+
// the regclass text needs the quoted name too, otherwise postgres folds a mixed case name to lower case
|
|
1283
|
+
const seq = this.platform.quoteValue(this.quote(seqName));
|
|
1282
1284
|
ret.push(`create sequence if not exists ${this.quote(seqName)}`);
|
|
1283
|
-
ret.push(`select setval(
|
|
1284
|
-
ret.push(`alter table ${this.quote(name)} alter column ${this.quote(column.name)} set default nextval(
|
|
1285
|
+
ret.push(`select setval(${seq}, (select max(${this.quote(column.name)}) from ${this.quote(name)}))`);
|
|
1286
|
+
ret.push(`alter table ${this.quote(name)} alter column ${this.quote(column.name)} set default nextval(${seq})`);
|
|
1285
1287
|
}
|
|
1286
1288
|
return ret;
|
|
1287
1289
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.10-dev.
|
|
3
|
+
"version": "7.2.10-dev.20",
|
|
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",
|
|
@@ -47,13 +47,13 @@
|
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"kysely": "0.29.
|
|
50
|
+
"kysely": "0.29.9"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@mikro-orm/core": "^7.2.9"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.10-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.10-dev.20"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -1031,6 +1031,11 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
1031
1031
|
*/
|
|
1032
1032
|
private processNestedJoins;
|
|
1033
1033
|
private hasToManyJoins;
|
|
1034
|
+
/**
|
|
1035
|
+
* Whether a join can match more than one row per root row. Only owning to-one joins target a unique key; inverse 1:1
|
|
1036
|
+
* relies on an unenforced unique FK, and sub-query or table reference joins match arbitrary rows.
|
|
1037
|
+
*/
|
|
1038
|
+
private canRepeatRootRows;
|
|
1034
1039
|
/**
|
|
1035
1040
|
* Resolves a `persist: false` virtual field referenced in `orderBy` (e.g. `qb.as('reviewCount')` or a
|
|
1036
1041
|
* `raw()` fragment aliased in the select) to the alias and SQL expression it was selected under. The
|
package/query/QueryBuilder.js
CHANGED
|
@@ -1117,7 +1117,7 @@ export class QueryBuilder {
|
|
|
1117
1117
|
if (Array.isArray(res)) {
|
|
1118
1118
|
const map = {};
|
|
1119
1119
|
mapped = res.map(r => this.driver.mapResult(r, meta, this.#state.populate, this, map));
|
|
1120
|
-
if (options.mergeResults && joinedProps.length > 0) {
|
|
1120
|
+
if (options.mergeResults && joinedProps.length > 0 && this.canRepeatRootRows()) {
|
|
1121
1121
|
mapped = this.driver.mergeJoinedResult(mapped, this.mainAlias.meta, joinedProps);
|
|
1122
1122
|
}
|
|
1123
1123
|
}
|
|
@@ -2274,6 +2274,17 @@ export class QueryBuilder {
|
|
|
2274
2274
|
return [ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(join.prop.kind);
|
|
2275
2275
|
});
|
|
2276
2276
|
}
|
|
2277
|
+
/**
|
|
2278
|
+
* Whether a join can match more than one row per root row. Only owning to-one joins target a unique key; inverse 1:1
|
|
2279
|
+
* relies on an unenforced unique FK, and sub-query or table reference joins match arbitrary rows.
|
|
2280
|
+
*/
|
|
2281
|
+
canRepeatRootRows() {
|
|
2282
|
+
return Object.values(this.#state.joins).some(join => {
|
|
2283
|
+
const { kind, owner, name } = join.prop;
|
|
2284
|
+
const uniqueTarget = kind === ReferenceKind.MANY_TO_ONE || (kind === ReferenceKind.ONE_TO_ONE && owner);
|
|
2285
|
+
return !uniqueTarget || join.subquery != null || name === '__subquery__';
|
|
2286
|
+
});
|
|
2287
|
+
}
|
|
2277
2288
|
/**
|
|
2278
2289
|
* Resolves a `persist: false` virtual field referenced in `orderBy` (e.g. `qb.as('reviewCount')` or a
|
|
2279
2290
|
* `raw()` fragment aliased in the select) to the alias and SQL expression it was selected under. The
|
|
@@ -9,7 +9,10 @@ export class ScalarCriteriaNode extends CriteriaNode {
|
|
|
9
9
|
process(qb, options) {
|
|
10
10
|
const matchPopulateJoins = options?.matchPopulateJoins ||
|
|
11
11
|
(this.prop && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(this.prop.kind));
|
|
12
|
-
|
|
12
|
+
// nodes without a property (e.g. `$in` items) never join, so the alias lookup is not needed
|
|
13
|
+
const nestedAlias = this.prop
|
|
14
|
+
? qb.getAliasForJoinPath(this.getPath(options), { ...options, matchPopulateJoins })
|
|
15
|
+
: undefined;
|
|
13
16
|
if (this.shouldJoin(qb, nestedAlias)) {
|
|
14
17
|
const path = this.getPath();
|
|
15
18
|
const parentPath = this.parent.getPath(); // the parent is always there, otherwise `shouldJoin` would return `false`
|