@mikro-orm/knex 5.8.3-dev.5 → 5.8.3-dev.7
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.d.ts +3 -4
- package/AbstractSqlDriver.js +19 -21
- package/package.json +4 -4
package/AbstractSqlDriver.d.ts
CHANGED
|
@@ -16,10 +16,9 @@ export declare abstract class AbstractSqlDriver<Connection extends AbstractSqlCo
|
|
|
16
16
|
find<T extends object, P extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOptions<T, P>): Promise<EntityData<T>[]>;
|
|
17
17
|
findOne<T extends object, P extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, P>): Promise<EntityData<T> | null>;
|
|
18
18
|
findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any>): Promise<EntityData<T>[]>;
|
|
19
|
-
countVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: CountOptions<T>): Promise<number>;
|
|
20
|
-
|
|
21
|
-
protected wrapVirtualExpressionInSubquery<T extends object>(meta: EntityMetadata<T>, expression: string, where: FilterQuery<T>, options: FindOptions<T, any>, type: QueryType
|
|
22
|
-
protected wrapVirtualExpressionInSubquery<T extends object>(meta: EntityMetadata<T>, expression: string, where: FilterQuery<T>, options: FindOptions<T, any>): Promise<T[]>;
|
|
19
|
+
countVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
|
|
20
|
+
private findFromVirtual;
|
|
21
|
+
protected wrapVirtualExpressionInSubquery<T extends object>(meta: EntityMetadata<T>, expression: string, where: FilterQuery<T>, options: FindOptions<T, any>, type: QueryType): Promise<T[] | number>;
|
|
23
22
|
mapResult<T extends object>(result: EntityData<T>, meta: EntityMetadata<T>, populate?: PopulateOptions<T>[], qb?: QueryBuilder<T>, map?: Dictionary): EntityData<T> | null;
|
|
24
23
|
private mapJoinedProps;
|
|
25
24
|
private appendToCollection;
|
package/AbstractSqlDriver.js
CHANGED
|
@@ -71,42 +71,38 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
71
71
|
return res[0] || null;
|
|
72
72
|
}
|
|
73
73
|
async findVirtual(entityName, where, options) {
|
|
74
|
-
|
|
75
|
-
/* istanbul ignore next */
|
|
76
|
-
if (!meta.expression) {
|
|
77
|
-
return [];
|
|
78
|
-
}
|
|
79
|
-
if (typeof meta.expression === 'string') {
|
|
80
|
-
return this.wrapVirtualExpressionInSubquery(meta, meta.expression, where, options);
|
|
81
|
-
}
|
|
82
|
-
const em = this.createEntityManager(false);
|
|
83
|
-
em.setTransactionContext(options.ctx);
|
|
84
|
-
const res = meta.expression(em, where, options);
|
|
85
|
-
if (res instanceof query_1.QueryBuilder) {
|
|
86
|
-
return this.wrapVirtualExpressionInSubquery(meta, res.getFormattedQuery(), where, options);
|
|
87
|
-
}
|
|
88
|
-
/* istanbul ignore next */
|
|
89
|
-
return res;
|
|
74
|
+
return this.findFromVirtual(entityName, where, options, query_1.QueryType.SELECT);
|
|
90
75
|
}
|
|
91
76
|
async countVirtual(entityName, where, options) {
|
|
77
|
+
return this.findFromVirtual(entityName, where, options, query_1.QueryType.COUNT);
|
|
78
|
+
}
|
|
79
|
+
async findFromVirtual(entityName, where, options, type) {
|
|
92
80
|
const meta = this.metadata.get(entityName);
|
|
93
81
|
/* istanbul ignore next */
|
|
94
82
|
if (!meta.expression) {
|
|
95
|
-
return 0;
|
|
83
|
+
return type === query_1.QueryType.SELECT ? [] : 0;
|
|
96
84
|
}
|
|
97
85
|
if (typeof meta.expression === 'string') {
|
|
98
|
-
return this.wrapVirtualExpressionInSubquery(meta, meta.expression, where, options,
|
|
86
|
+
return this.wrapVirtualExpressionInSubquery(meta, meta.expression, where, options, type);
|
|
99
87
|
}
|
|
100
88
|
const em = this.createEntityManager(false);
|
|
101
89
|
em.setTransactionContext(options.ctx);
|
|
102
90
|
const res = meta.expression(em, where, options);
|
|
91
|
+
if (typeof res === 'string') {
|
|
92
|
+
return this.wrapVirtualExpressionInSubquery(meta, res, where, options, type);
|
|
93
|
+
}
|
|
103
94
|
if (res instanceof query_1.QueryBuilder) {
|
|
104
|
-
return this.wrapVirtualExpressionInSubquery(meta, res.getFormattedQuery(), where, options,
|
|
95
|
+
return this.wrapVirtualExpressionInSubquery(meta, res.getFormattedQuery(), where, options, type);
|
|
96
|
+
}
|
|
97
|
+
if (core_1.Utils.isObject(res)) {
|
|
98
|
+
const { sql, bindings } = res.toSQL();
|
|
99
|
+
const query = this.platform.formatQuery(sql, bindings);
|
|
100
|
+
return this.wrapVirtualExpressionInSubquery(meta, query, where, options, type);
|
|
105
101
|
}
|
|
106
102
|
/* istanbul ignore next */
|
|
107
103
|
return res;
|
|
108
104
|
}
|
|
109
|
-
async wrapVirtualExpressionInSubquery(meta, expression, where, options, type
|
|
105
|
+
async wrapVirtualExpressionInSubquery(meta, expression, where, options, type) {
|
|
110
106
|
const qb = this.createQueryBuilder(meta.className, options?.ctx, options.connectionType, options.convertCustomTypes)
|
|
111
107
|
.limit(options?.limit, options?.offset)
|
|
112
108
|
.indexHint(options.indexHint)
|
|
@@ -159,10 +155,12 @@ class AbstractSqlDriver extends core_1.DatabaseDriver {
|
|
|
159
155
|
return root[`${relationAlias}__${name}`] != null;
|
|
160
156
|
}));
|
|
161
157
|
if (!hasPK) {
|
|
162
|
-
// initialize empty collections
|
|
163
158
|
if ([core_1.ReferenceType.MANY_TO_MANY, core_1.ReferenceType.ONE_TO_MANY].includes(relation.reference)) {
|
|
164
159
|
result[relation.name] = result[relation.name] || [];
|
|
165
160
|
}
|
|
161
|
+
if ([core_1.ReferenceType.MANY_TO_ONE, core_1.ReferenceType.ONE_TO_ONE].includes(relation.reference)) {
|
|
162
|
+
result[relation.name] = null;
|
|
163
|
+
}
|
|
166
164
|
return;
|
|
167
165
|
}
|
|
168
166
|
meta2.props
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "5.8.3-dev.
|
|
3
|
+
"version": "5.8.3-dev.7",
|
|
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.8.2"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "~5.8.3-dev.
|
|
70
|
-
"@mikro-orm/entity-generator": "~5.8.3-dev.
|
|
71
|
-
"@mikro-orm/migrations": "~5.8.3-dev.
|
|
69
|
+
"@mikro-orm/core": "~5.8.3-dev.7",
|
|
70
|
+
"@mikro-orm/entity-generator": "~5.8.3-dev.7",
|
|
71
|
+
"@mikro-orm/migrations": "~5.8.3-dev.7",
|
|
72
72
|
"better-sqlite3": "*",
|
|
73
73
|
"mssql": "*",
|
|
74
74
|
"mysql": "*",
|