@mikro-orm/sql 7.2.9-dev.2 → 7.2.9-dev.4
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/query/QueryBuilder.d.ts +5 -0
- package/query/QueryBuilder.js +16 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.2.9-dev.
|
|
3
|
+
"version": "7.2.9-dev.4",
|
|
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.2.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.2.9-dev.
|
|
56
|
+
"@mikro-orm/core": "7.2.9-dev.4"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
package/query/QueryBuilder.d.ts
CHANGED
|
@@ -803,6 +803,11 @@ export declare class QueryBuilder<Entity extends object = AnyEntity, RootAlias e
|
|
|
803
803
|
* Use `method` to specify what kind of result you want to get (array/single/meta).
|
|
804
804
|
*/
|
|
805
805
|
execute<U = any>(method?: 'all' | 'get' | 'run', options?: ExecuteOptions | boolean): Promise<U>;
|
|
806
|
+
/**
|
|
807
|
+
* An update or delete with auto-joined conditions stays a select until `finalize()` wraps it,
|
|
808
|
+
* so read the same flags `wrapModifySubQuery()` uses.
|
|
809
|
+
*/
|
|
810
|
+
private getExecuteType;
|
|
806
811
|
private getConnection;
|
|
807
812
|
/**
|
|
808
813
|
* Executes the query and returns an async iterable (async generator) that yields results one by one.
|
package/query/QueryBuilder.js
CHANGED
|
@@ -1067,12 +1067,13 @@ export class QueryBuilder {
|
|
|
1067
1067
|
options = typeof options === 'boolean' ? { mapResults: options } : (options ?? {});
|
|
1068
1068
|
options.mergeResults ??= true;
|
|
1069
1069
|
options.mapResults ??= true;
|
|
1070
|
-
const
|
|
1070
|
+
const type = this.getExecuteType();
|
|
1071
|
+
const isRunType = [QueryType.INSERT, QueryType.UPDATE, QueryType.DELETE, QueryType.TRUNCATE].includes(type);
|
|
1071
1072
|
method ??= isRunType ? 'run' : 'all';
|
|
1072
1073
|
if (!this.connectionType && (isRunType || this.context)) {
|
|
1073
1074
|
this.connectionType = 'write';
|
|
1074
1075
|
}
|
|
1075
|
-
if (!this.#state.finalized && method === 'get' &&
|
|
1076
|
+
if (!this.#state.finalized && method === 'get' && type === QueryType.SELECT) {
|
|
1076
1077
|
this.limit(1);
|
|
1077
1078
|
}
|
|
1078
1079
|
const query = this.toQuery();
|
|
@@ -1130,6 +1131,19 @@ export class QueryBuilder {
|
|
|
1130
1131
|
await this.em?.storeCache(this.#state.cache, cached, mapped);
|
|
1131
1132
|
return mapped;
|
|
1132
1133
|
}
|
|
1134
|
+
/**
|
|
1135
|
+
* An update or delete with auto-joined conditions stays a select until `finalize()` wraps it,
|
|
1136
|
+
* so read the same flags `wrapModifySubQuery()` uses.
|
|
1137
|
+
*/
|
|
1138
|
+
getExecuteType() {
|
|
1139
|
+
if (this.#state.flags.has(QueryFlag.UPDATE_SUB_QUERY)) {
|
|
1140
|
+
return QueryType.UPDATE;
|
|
1141
|
+
}
|
|
1142
|
+
if (this.#state.flags.has(QueryFlag.DELETE_SUB_QUERY)) {
|
|
1143
|
+
return QueryType.DELETE;
|
|
1144
|
+
}
|
|
1145
|
+
return this.type;
|
|
1146
|
+
}
|
|
1133
1147
|
getConnection() {
|
|
1134
1148
|
const write = !this.platform.getConfig().get('preferReadReplicas');
|
|
1135
1149
|
const type = this.connectionType || (write ? 'write' : 'read');
|