@mikro-orm/sql 7.1.9-dev.16 → 7.1.9-dev.18
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.
|
@@ -56,6 +56,15 @@ export declare abstract class AbstractSqlConnection extends Connection {
|
|
|
56
56
|
commit(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
|
|
57
57
|
/** Rolls back the transaction or rolls back to the savepoint. */
|
|
58
58
|
rollback(ctx: ControlledTransaction<any, any>, eventBroadcaster?: TransactionEventBroadcaster, loggerContext?: LogContext): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Waits until the transaction's connection has no query in flight. Kysely runs `rollback` straight
|
|
61
|
+
* on that connection instead of going through its connection provider, so a rollback caused by an
|
|
62
|
+
* aborted query would otherwise be sent while the aborted query is still running. That not only
|
|
63
|
+
* queues the rollback behind it on the server, it also overwrites the query id Kysely compares
|
|
64
|
+
* against before firing the `'cancel query'`/`'kill session'` control statement — the control
|
|
65
|
+
* statement is then discarded as stale and the abort never reaches the database.
|
|
66
|
+
*/
|
|
67
|
+
private waitForIdleTransaction;
|
|
59
68
|
private prepareQuery;
|
|
60
69
|
/** Executes a SQL query and returns the result based on the method: `'all'` for rows, `'get'` for single row, `'run'` for affected count. */
|
|
61
70
|
execute<T extends QueryResult | EntityData<AnyEntity> | EntityData<AnyEntity>[] = EntityData<AnyEntity>[]>(query: string | NativeQueryBuilder | RawQueryFragment, params?: readonly unknown[], method?: 'all' | 'get' | 'run', ctx?: Transaction, loggerContext?: LoggingOptions): Promise<T>;
|
package/AbstractSqlConnection.js
CHANGED
|
@@ -171,6 +171,7 @@ export class AbstractSqlConnection extends Connection {
|
|
|
171
171
|
/** Rolls back the transaction or rolls back to the savepoint. */
|
|
172
172
|
async rollback(ctx, eventBroadcaster, loggerContext) {
|
|
173
173
|
await eventBroadcaster?.dispatchEvent(EventType.beforeTransactionRollback, ctx);
|
|
174
|
+
await this.waitForIdleTransaction(ctx);
|
|
174
175
|
if ('savepointName' in ctx) {
|
|
175
176
|
await ctx.rollbackToSavepoint(ctx.savepointName).execute();
|
|
176
177
|
this.logQuery(this.platform.getRollbackToSavepointSQL(ctx.savepointName), loggerContext);
|
|
@@ -181,6 +182,17 @@ export class AbstractSqlConnection extends Connection {
|
|
|
181
182
|
}
|
|
182
183
|
await eventBroadcaster?.dispatchEvent(EventType.afterTransactionRollback, ctx);
|
|
183
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Waits until the transaction's connection has no query in flight. Kysely runs `rollback` straight
|
|
187
|
+
* on that connection instead of going through its connection provider, so a rollback caused by an
|
|
188
|
+
* aborted query would otherwise be sent while the aborted query is still running. That not only
|
|
189
|
+
* queues the rollback behind it on the server, it also overwrites the query id Kysely compares
|
|
190
|
+
* against before firing the `'cancel query'`/`'kill session'` control statement — the control
|
|
191
|
+
* statement is then discarded as stale and the abort never reaches the database.
|
|
192
|
+
*/
|
|
193
|
+
async waitForIdleTransaction(ctx) {
|
|
194
|
+
await ctx.getExecutor().provideConnection(async () => undefined);
|
|
195
|
+
}
|
|
184
196
|
prepareQuery(query, params = []) {
|
|
185
197
|
if (query instanceof NativeQueryBuilder) {
|
|
186
198
|
query = query.toRaw();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/sql",
|
|
3
|
-
"version": "7.1.9-dev.
|
|
3
|
+
"version": "7.1.9-dev.18",
|
|
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.8"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@mikro-orm/core": "7.1.9-dev.
|
|
56
|
+
"@mikro-orm/core": "7.1.9-dev.18"
|
|
57
57
|
},
|
|
58
58
|
"engines": {
|
|
59
59
|
"node": ">= 22.17.0"
|
|
@@ -54,6 +54,8 @@ export declare class SqlSchemaGenerator extends AbstractSchemaGenerator<Abstract
|
|
|
54
54
|
wrap?: boolean;
|
|
55
55
|
ctx?: Transaction;
|
|
56
56
|
}): Promise<void>;
|
|
57
|
+
/** Whether the statement has to be the first one in a query batch, e.g. `create trigger` on MSSQL. */
|
|
58
|
+
protected startsBatch(_statement: string): boolean;
|
|
57
59
|
dropTableIfExists(name: string, schema?: string): Promise<void>;
|
|
58
60
|
private wrapSchema;
|
|
59
61
|
private append;
|
|
@@ -443,14 +443,19 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
443
443
|
const groups = [];
|
|
444
444
|
let i = 0;
|
|
445
445
|
for (const line of lines) {
|
|
446
|
-
|
|
446
|
+
const stmt = line.trim();
|
|
447
|
+
if (stmt === '') {
|
|
447
448
|
if (groups[i]?.length > 0) {
|
|
448
449
|
i++;
|
|
449
450
|
}
|
|
450
451
|
continue;
|
|
451
452
|
}
|
|
453
|
+
// same boundary an empty line creates, for statements that have to start their own batch
|
|
454
|
+
if (groups[i]?.length > 0 && this.startsBatch(stmt)) {
|
|
455
|
+
i++;
|
|
456
|
+
}
|
|
452
457
|
groups[i] ??= [];
|
|
453
|
-
groups[i].push(
|
|
458
|
+
groups[i].push(stmt);
|
|
454
459
|
}
|
|
455
460
|
if (groups.length === 0) {
|
|
456
461
|
return;
|
|
@@ -471,6 +476,10 @@ export class SqlSchemaGenerator extends AbstractSchemaGenerator {
|
|
|
471
476
|
});
|
|
472
477
|
await Utils.runSerial(statements, stmt => this.driver.execute(stmt));
|
|
473
478
|
}
|
|
479
|
+
/** Whether the statement has to be the first one in a query batch, e.g. `create trigger` on MSSQL. */
|
|
480
|
+
startsBatch(_statement) {
|
|
481
|
+
return false;
|
|
482
|
+
}
|
|
474
483
|
async dropTableIfExists(name, schema) {
|
|
475
484
|
const sql = this.helper.dropTableIfExists(name, schema);
|
|
476
485
|
return this.execute(sql);
|