@breautek/storm 4.5.0 → 4.6.1

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.
Files changed (90) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/docs/README.md +6 -5
  3. package/docs/classes/Application.md +26 -26
  4. package/docs/classes/BackendAuthenticationMiddleware.md +2 -2
  5. package/docs/classes/CORSMiddleware.md +6 -6
  6. package/docs/classes/ConfigLoader.md +1 -1
  7. package/docs/classes/Database.md +12 -12
  8. package/docs/classes/DatabaseCastObject.md +3 -3
  9. package/docs/classes/DatabaseConnection.md +26 -20
  10. package/docs/classes/DatabaseQueryError.md +10 -10
  11. package/docs/classes/DeadLockError.md +10 -10
  12. package/docs/classes/DiskSpaceError.md +10 -10
  13. package/docs/classes/DropTemporaryTableQuery.md +8 -8
  14. package/docs/classes/DumpStream.md +1 -1
  15. package/docs/classes/DuplicateEntryError.md +10 -10
  16. package/docs/classes/EntityNotFoundError.md +10 -10
  17. package/docs/classes/ExpiredTokenError.md +10 -10
  18. package/docs/classes/Handler.md +14 -14
  19. package/docs/classes/InternalError.md +10 -10
  20. package/docs/classes/InvalidCredentialsError.md +10 -10
  21. package/docs/classes/InvalidValueError.md +10 -10
  22. package/docs/classes/LineString.md +4 -4
  23. package/docs/classes/ManagedDatabaseConnection.md +26 -20
  24. package/docs/classes/Middleware.md +3 -3
  25. package/docs/classes/MissingConfigError.md +10 -10
  26. package/docs/classes/MissingParameterError.md +10 -10
  27. package/docs/classes/MySQLConnection.md +27 -21
  28. package/docs/classes/MySQLDatabase.md +13 -13
  29. package/docs/classes/NotImplementedError.md +10 -10
  30. package/docs/classes/Point.md +4 -4
  31. package/docs/classes/Polygon.md +4 -4
  32. package/docs/classes/Query.md +8 -8
  33. package/docs/classes/RawError.md +10 -10
  34. package/docs/classes/RawQuery.md +8 -8
  35. package/docs/classes/Request.md +18 -18
  36. package/docs/classes/Response.md +11 -11
  37. package/docs/classes/ResponseData.md +7 -7
  38. package/docs/classes/ServiceProvider.md +15 -15
  39. package/docs/classes/ServiceResponse.md +4 -4
  40. package/docs/classes/SetSessionVariableQuery.md +8 -8
  41. package/docs/classes/StormError.md +10 -10
  42. package/docs/classes/TemporaryTableQuery.md +8 -8
  43. package/docs/classes/Token.md +2 -2
  44. package/docs/classes/TokenManager.md +4 -4
  45. package/docs/classes/UnauthorizedAccessError.md +10 -10
  46. package/docs/enums/ErrorCode.md +9 -9
  47. package/docs/enums/ExitCode.md +2 -2
  48. package/docs/enums/HTTPMethod.md +4 -4
  49. package/docs/enums/IsolationLevel.md +52 -0
  50. package/docs/enums/JWTError.md +2 -2
  51. package/docs/enums/StatusCode.md +48 -48
  52. package/docs/interfaces/IConfig.md +8 -8
  53. package/docs/interfaces/IDatabaseConfig.md +6 -6
  54. package/docs/interfaces/IDatabaseConnection.md +21 -15
  55. package/docs/interfaces/IErrorResponse.md +5 -5
  56. package/docs/interfaces/IFormData.md +2 -2
  57. package/docs/interfaces/IHandler.md +1 -1
  58. package/docs/interfaces/IInsertQueryResult.md +3 -3
  59. package/docs/interfaces/IJWTVerifyOptions.md +1 -1
  60. package/docs/interfaces/IRequestResponse.md +2 -2
  61. package/docs/interfaces/ISetSessionVariableQueryInput.md +2 -2
  62. package/docs/interfaces/ITemporaryTableQueryInput.md +2 -2
  63. package/docs/interfaces/IUpdateQueryResult.md +2 -2
  64. package/jest.config.js +5 -1
  65. package/lib/DatabaseConnection.d.ts +2 -1
  66. package/lib/DatabaseConnection.js.map +1 -1
  67. package/lib/IDatabaseConnection.d.ts +2 -1
  68. package/lib/IsolationLevel.d.ts +6 -0
  69. package/lib/IsolationLevel.js +26 -0
  70. package/lib/IsolationLevel.js.map +1 -0
  71. package/lib/ManagedDatabaseConnection.d.ts +2 -1
  72. package/lib/ManagedDatabaseConnection.js +2 -2
  73. package/lib/ManagedDatabaseConnection.js.map +1 -1
  74. package/lib/MySQLConnection.d.ts +2 -1
  75. package/lib/MySQLConnection.js +15 -12
  76. package/lib/MySQLConnection.js.map +1 -1
  77. package/lib/api.d.ts +1 -0
  78. package/lib/api.js +4 -1
  79. package/lib/api.js.map +1 -1
  80. package/lib/private/SetIsolationLevelQuery.d.ts +5 -0
  81. package/lib/private/SetIsolationLevelQuery.js +42 -0
  82. package/lib/private/SetIsolationLevelQuery.js.map +1 -0
  83. package/package.json +1 -1
  84. package/src/DatabaseConnection.ts +2 -1
  85. package/src/IDatabaseConnection.ts +2 -1
  86. package/src/IsolationLevel.ts +22 -0
  87. package/src/ManagedDatabaseConnection.ts +3 -2
  88. package/src/MySQLConnection.ts +16 -12
  89. package/src/api.ts +1 -0
  90. package/src/private/SetIsolationLevelQuery.ts +39 -0
@@ -27,6 +27,8 @@ import * as SQLFormatter from 'sql-formatter';
27
27
  import { Logger, LogLevel } from '@arashi/logger';
28
28
  import { StormError } from './StormError';
29
29
  import { DeadLockError } from './DeadLockError';
30
+ import { IsolationLevel } from './IsolationLevel';
31
+ import {SetIsolationLevelQuery} from './private/SetIsolationLevelQuery';
30
32
 
31
33
  const DEFAULT_HIGH_WATERMARK: number = 512; // in number of result objects
32
34
  const TAG: string = 'MySQLConnection';
@@ -141,26 +143,28 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
141
143
  return queryObject.stream(streamOptions);
142
144
  }
143
145
 
144
- public startTransaction(): Promise<void> {
146
+ public override async startTransaction(isolationLevel?: IsolationLevel): Promise<void> {
145
147
  if (this.isReadOnly()) {
146
- return Promise.reject(new Error('A readonly connection cannot start a transaction.'));
148
+ throw new Error('A readonly connection cannot start a transaction.')
147
149
  }
148
150
 
149
151
  if (this.isTransaction()) {
150
- return Promise.reject(new Error('Connection is already in a transaction.'));
152
+ throw new Error('Connection is already in a transaction.');
151
153
  }
152
154
 
153
155
  this.$transaction = true;
154
156
 
155
- return new Promise<void>((resolve, reject) => {
156
- this.query(startTransactionQuery).then(() => {
157
- resolve();
158
- }).catch((ex) => {
159
- this.$transaction = false;
160
- getInstance().getLogger().error(TAG, ex);
161
- reject(ex);
162
- });
163
- });
157
+ try {
158
+ if (isolationLevel) {
159
+ await new SetIsolationLevelQuery(isolationLevel).execute(this);
160
+ }
161
+ await startTransactionQuery.execute(this);
162
+ }
163
+ catch (ex) {
164
+ this.$transaction = false;
165
+ getInstance().getLogger().error(TAG, ex);
166
+ throw ex;
167
+ }
164
168
  }
165
169
 
166
170
  public endTransaction(requiresRollback: boolean = false): Promise<void> {
package/src/api.ts CHANGED
@@ -35,6 +35,7 @@ export {IInsertQueryResult} from './IInsertQueryResult';
35
35
  export {IDeleteQueryResult} from './IDeleteQueryResult';
36
36
  export {IUpdateQueryResult} from './IUpdateQueryResult';
37
37
  export {SetSessionVariableQuery, ISetSessionVariableQueryInput} from './SetSessionVariableQuery';
38
+ export {IsolationLevel} from './IsolationLevel';
38
39
 
39
40
  // Errors
40
41
  export {ErrorCode} from './ErrorCode';
@@ -0,0 +1,39 @@
1
+ /*
2
+ Copyright 2017-2021 Norman Breau
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ import { IsolationLevel } from '../IsolationLevel';
18
+ import {Query} from '../Query';
19
+
20
+ export class SetIsolationLevelQuery extends Query<IsolationLevel, void> {
21
+ protected _getQuery(): string {
22
+ let level: string;
23
+ switch (this.getParameters()) {
24
+ case IsolationLevel.READ_COMMITTED:
25
+ level = 'READ COMMITTED';
26
+ break;
27
+ case IsolationLevel.READ_UNCOMMITTED:
28
+ level = 'READ UNCOMMITTED';
29
+ break;
30
+ case IsolationLevel.REPEATABLE_READ:
31
+ level = 'REPEATABLE READ';
32
+ break;
33
+ case IsolationLevel.SERIALIZABLE:
34
+ level = 'SERIALIZABLE';
35
+ break;
36
+ }
37
+ return `SET TRANSACTION ISOLATION LEVEL ${level}`;
38
+ }
39
+ }