typeorm 0.3.7-dev.bcdddc3 → 0.3.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.
File without changes
File without changes
@@ -52,6 +52,13 @@ export declare class SapQueryRunner extends BaseQueryRunner implements QueryRunn
52
52
  * Error will be thrown if transaction was not started.
53
53
  */
54
54
  rollbackTransaction(): Promise<void>;
55
+ /**
56
+ * @description Switches on/off AUTOCOMMIT mode
57
+ * @link https://help.sap.com/docs/HANA_SERVICE_CF/7c78579ce9b14a669c1f3295b0d8ca16/d538d11053bd4f3f847ec5ce817a3d4c.html?locale=en-US
58
+ */
59
+ setAutoCommit(options: {
60
+ status: "on" | "off";
61
+ }): Promise<void>;
55
62
  /**
56
63
  * Executes a given SQL query.
57
64
  */
@@ -17,6 +17,7 @@ import { QueryResult } from "../../query-runner/QueryResult";
17
17
  import { QueryLock } from "../../query-runner/QueryLock";
18
18
  import { MetadataTableType } from "../types/MetadataTableType";
19
19
  import { InstanceChecker } from "../../util/InstanceChecker";
20
+ import { promisify } from "util";
20
21
  /**
21
22
  * Runs queries on a single SQL Server database connection.
22
23
  */
@@ -67,6 +68,11 @@ export class SapQueryRunner extends BaseQueryRunner {
67
68
  throw new TransactionAlreadyStartedError();
68
69
  await this.broadcaster.broadcast("BeforeTransactionStart");
69
70
  this.isTransactionActive = true;
71
+ /**
72
+ * Disable AUTOCOMMIT while running transaction.
73
+ * Otherwise, COMMIT/ROLLBACK doesn't work in autocommit mode.
74
+ */
75
+ await this.setAutoCommit({ status: "off" });
70
76
  if (isolationLevel) {
71
77
  await this.query(`SET TRANSACTION ISOLATION LEVEL ${isolationLevel || ""}`);
72
78
  }
@@ -84,6 +90,7 @@ export class SapQueryRunner extends BaseQueryRunner {
84
90
  await this.broadcaster.broadcast("BeforeTransactionCommit");
85
91
  await this.query("COMMIT");
86
92
  this.isTransactionActive = false;
93
+ await this.setAutoCommit({ status: "on" });
87
94
  await this.broadcaster.broadcast("AfterTransactionCommit");
88
95
  }
89
96
  /**
@@ -98,8 +105,25 @@ export class SapQueryRunner extends BaseQueryRunner {
98
105
  await this.broadcaster.broadcast("BeforeTransactionRollback");
99
106
  await this.query("ROLLBACK");
100
107
  this.isTransactionActive = false;
108
+ await this.setAutoCommit({ status: "on" });
101
109
  await this.broadcaster.broadcast("AfterTransactionRollback");
102
110
  }
111
+ /**
112
+ * @description Switches on/off AUTOCOMMIT mode
113
+ * @link https://help.sap.com/docs/HANA_SERVICE_CF/7c78579ce9b14a669c1f3295b0d8ca16/d538d11053bd4f3f847ec5ce817a3d4c.html?locale=en-US
114
+ */
115
+ async setAutoCommit(options) {
116
+ const connection = await this.connect();
117
+ const execute = promisify(connection.exec.bind(connection));
118
+ connection.setAutoCommit(options.status === "on");
119
+ const query = `SET TRANSACTION AUTOCOMMIT DDL ${options.status.toUpperCase()};`;
120
+ try {
121
+ await execute(query);
122
+ }
123
+ catch (error) {
124
+ throw new QueryFailedError(query, [], error);
125
+ }
126
+ }
103
127
  /**
104
128
  * Executes a given SQL query.
105
129
  */
@@ -111,8 +135,6 @@ export class SapQueryRunner extends BaseQueryRunner {
111
135
  const result = new QueryResult();
112
136
  try {
113
137
  const databaseConnection = await this.connect();
114
- // we disable autocommit because ROLLBACK does not work in autocommit mode
115
- databaseConnection.setAutoCommit(!this.isTransactionActive);
116
138
  this.driver.connection.logger.logQuery(query, parameters, this);
117
139
  const queryStartTime = +new Date();
118
140
  const isInsertQuery = query.substr(0, 11) === "INSERT INTO";