@mikro-orm/sql 7.2.0-dev.15 → 7.2.0-dev.16
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/AbstractSqlPlatform.d.ts +3 -1
- package/AbstractSqlPlatform.js +32 -1
- package/package.json +2 -2
package/AbstractSqlPlatform.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type RawQueryFragment, type Constructor, type EntityManager, type EntityRepository, type IDatabaseDriver, type IsolationLevel, type MikroORM, Platform } from '@mikro-orm/core';
|
|
1
|
+
import { type RawQueryFragment, type Constructor, type EntityManager, type EntityProperty, type EntityRepository, type FormulaColumns, type IDatabaseDriver, type IsolationLevel, type MikroORM, Platform } from '@mikro-orm/core';
|
|
2
2
|
import { SqlSchemaGenerator } from './schema/SqlSchemaGenerator.js';
|
|
3
3
|
import { type SchemaHelper } from './schema/SchemaHelper.js';
|
|
4
4
|
import type { IndexDef } from './typings.js';
|
|
@@ -17,6 +17,8 @@ export declare abstract class AbstractSqlPlatform extends Platform {
|
|
|
17
17
|
getSchemaGenerator(driver: IDatabaseDriver, em?: EntityManager): SqlSchemaGenerator;
|
|
18
18
|
/** @internal */
|
|
19
19
|
createNativeQueryBuilder(): NativeQueryBuilder;
|
|
20
|
+
/** @inheritDoc */
|
|
21
|
+
getThroughRelationFormula(prop: EntityProperty, columns: FormulaColumns<any>): string;
|
|
20
22
|
getBeginTransactionSQL(options?: {
|
|
21
23
|
isolationLevel?: IsolationLevel;
|
|
22
24
|
readOnly?: boolean;
|
package/AbstractSqlPlatform.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isRaw, JsonProperty, Platform, raw, Utils, } from '@mikro-orm/core';
|
|
1
|
+
import { isRaw, JsonProperty, Platform, raw, Utils, ValidationError, } from '@mikro-orm/core';
|
|
2
2
|
import { SqlEntityRepository } from './SqlEntityRepository.js';
|
|
3
3
|
import { SqlSchemaGenerator } from './schema/SqlSchemaGenerator.js';
|
|
4
4
|
import { NativeQueryBuilder } from './query/NativeQueryBuilder.js';
|
|
@@ -39,6 +39,37 @@ export class AbstractSqlPlatform extends Platform {
|
|
|
39
39
|
createNativeQueryBuilder() {
|
|
40
40
|
return new NativeQueryBuilder(this);
|
|
41
41
|
}
|
|
42
|
+
/** @inheritDoc */
|
|
43
|
+
getThroughRelationFormula(prop, columns) {
|
|
44
|
+
const through = prop.through;
|
|
45
|
+
const driver = this.config.getDriver();
|
|
46
|
+
const alias = `${prop.name}_through`;
|
|
47
|
+
const qb = driver.createQueryBuilder(through.entity, undefined, 'read', true, undefined, alias);
|
|
48
|
+
const throughMeta = driver.getMetadata().get(through.entity);
|
|
49
|
+
const ownerProp = throughMeta.properties[through.ownerProperty];
|
|
50
|
+
const ownerMeta = driver.getMetadata().get(ownerProp.target);
|
|
51
|
+
ownerProp.fieldNames.forEach((fieldName, idx) => {
|
|
52
|
+
const referencedColumn = ownerProp.referencedColumnNames[idx];
|
|
53
|
+
const referencedProp = ownerProp.referencedPKs
|
|
54
|
+
.map(name => ownerMeta.properties[name])
|
|
55
|
+
.find(p => p.fieldNames.includes(referencedColumn));
|
|
56
|
+
// the column mapping resolves the right alias even for TPT owners, only the column name may differ for composite FK properties
|
|
57
|
+
const ownerAlias = columns[referencedProp.name].slice(0, columns[referencedProp.name].lastIndexOf('.'));
|
|
58
|
+
qb.andWhere(raw('?? = ??', [`${alias}.${fieldName}`, `${ownerAlias}.${referencedColumn}`]));
|
|
59
|
+
});
|
|
60
|
+
if (through.where) {
|
|
61
|
+
qb.andWhere(through.where);
|
|
62
|
+
}
|
|
63
|
+
if (through.orderBy) {
|
|
64
|
+
qb.orderBy(through.orderBy);
|
|
65
|
+
}
|
|
66
|
+
qb.select(through.targetProperty ?? throughMeta.primaryKeys[0]).limit(1);
|
|
67
|
+
const sql = qb.getFormattedQuery();
|
|
68
|
+
if (Object.keys(qb.state.joins).length > 0) {
|
|
69
|
+
throw new ValidationError(`The 'where' and 'orderBy' options of the through relation ${prop.name} can only reference own columns of ${throughMeta.className}`);
|
|
70
|
+
}
|
|
71
|
+
return `(${sql})`;
|
|
72
|
+
}
|
|
42
73
|
getBeginTransactionSQL(options) {
|
|
43
74
|
if (options?.isolationLevel) {
|
|
44
75
|
return [`set transaction isolation level ${options.isolationLevel}`, 'begin'];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.0-dev.
|
|
3
|
+
"version": "7.2.0-dev.16",
|
|
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.15"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.0-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.0-dev.16"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|