@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.
- package/CHANGELOG.md +12 -0
- package/docs/README.md +6 -5
- package/docs/classes/Application.md +26 -26
- package/docs/classes/BackendAuthenticationMiddleware.md +2 -2
- package/docs/classes/CORSMiddleware.md +6 -6
- package/docs/classes/ConfigLoader.md +1 -1
- package/docs/classes/Database.md +12 -12
- package/docs/classes/DatabaseCastObject.md +3 -3
- package/docs/classes/DatabaseConnection.md +26 -20
- package/docs/classes/DatabaseQueryError.md +10 -10
- package/docs/classes/DeadLockError.md +10 -10
- package/docs/classes/DiskSpaceError.md +10 -10
- package/docs/classes/DropTemporaryTableQuery.md +8 -8
- package/docs/classes/DumpStream.md +1 -1
- package/docs/classes/DuplicateEntryError.md +10 -10
- package/docs/classes/EntityNotFoundError.md +10 -10
- package/docs/classes/ExpiredTokenError.md +10 -10
- package/docs/classes/Handler.md +14 -14
- package/docs/classes/InternalError.md +10 -10
- package/docs/classes/InvalidCredentialsError.md +10 -10
- package/docs/classes/InvalidValueError.md +10 -10
- package/docs/classes/LineString.md +4 -4
- package/docs/classes/ManagedDatabaseConnection.md +26 -20
- package/docs/classes/Middleware.md +3 -3
- package/docs/classes/MissingConfigError.md +10 -10
- package/docs/classes/MissingParameterError.md +10 -10
- package/docs/classes/MySQLConnection.md +27 -21
- package/docs/classes/MySQLDatabase.md +13 -13
- package/docs/classes/NotImplementedError.md +10 -10
- package/docs/classes/Point.md +4 -4
- package/docs/classes/Polygon.md +4 -4
- package/docs/classes/Query.md +8 -8
- package/docs/classes/RawError.md +10 -10
- package/docs/classes/RawQuery.md +8 -8
- package/docs/classes/Request.md +18 -18
- package/docs/classes/Response.md +11 -11
- package/docs/classes/ResponseData.md +7 -7
- package/docs/classes/ServiceProvider.md +15 -15
- package/docs/classes/ServiceResponse.md +4 -4
- package/docs/classes/SetSessionVariableQuery.md +8 -8
- package/docs/classes/StormError.md +10 -10
- package/docs/classes/TemporaryTableQuery.md +8 -8
- package/docs/classes/Token.md +2 -2
- package/docs/classes/TokenManager.md +4 -4
- package/docs/classes/UnauthorizedAccessError.md +10 -10
- package/docs/enums/ErrorCode.md +9 -9
- package/docs/enums/ExitCode.md +2 -2
- package/docs/enums/HTTPMethod.md +4 -4
- package/docs/enums/IsolationLevel.md +52 -0
- package/docs/enums/JWTError.md +2 -2
- package/docs/enums/StatusCode.md +48 -48
- package/docs/interfaces/IConfig.md +8 -8
- package/docs/interfaces/IDatabaseConfig.md +6 -6
- package/docs/interfaces/IDatabaseConnection.md +21 -15
- package/docs/interfaces/IErrorResponse.md +5 -5
- package/docs/interfaces/IFormData.md +2 -2
- package/docs/interfaces/IHandler.md +1 -1
- package/docs/interfaces/IInsertQueryResult.md +3 -3
- package/docs/interfaces/IJWTVerifyOptions.md +1 -1
- package/docs/interfaces/IRequestResponse.md +2 -2
- package/docs/interfaces/ISetSessionVariableQueryInput.md +2 -2
- package/docs/interfaces/ITemporaryTableQueryInput.md +2 -2
- package/docs/interfaces/IUpdateQueryResult.md +2 -2
- package/jest.config.js +5 -1
- package/lib/DatabaseConnection.d.ts +2 -1
- package/lib/DatabaseConnection.js.map +1 -1
- package/lib/IDatabaseConnection.d.ts +2 -1
- package/lib/IsolationLevel.d.ts +6 -0
- package/lib/IsolationLevel.js +26 -0
- package/lib/IsolationLevel.js.map +1 -0
- package/lib/ManagedDatabaseConnection.d.ts +2 -1
- package/lib/ManagedDatabaseConnection.js +2 -2
- package/lib/ManagedDatabaseConnection.js.map +1 -1
- package/lib/MySQLConnection.d.ts +2 -1
- package/lib/MySQLConnection.js +15 -12
- package/lib/MySQLConnection.js.map +1 -1
- package/lib/api.d.ts +1 -0
- package/lib/api.js +4 -1
- package/lib/api.js.map +1 -1
- package/lib/private/SetIsolationLevelQuery.d.ts +5 -0
- package/lib/private/SetIsolationLevelQuery.js +42 -0
- package/lib/private/SetIsolationLevelQuery.js.map +1 -0
- package/package.json +1 -1
- package/src/DatabaseConnection.ts +2 -1
- package/src/IDatabaseConnection.ts +2 -1
- package/src/IsolationLevel.ts +22 -0
- package/src/ManagedDatabaseConnection.ts +3 -2
- package/src/MySQLConnection.ts +16 -12
- package/src/api.ts +1 -0
- package/src/private/SetIsolationLevelQuery.ts +39 -0
package/src/MySQLConnection.ts
CHANGED
|
@@ -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
|
-
|
|
148
|
+
throw new Error('A readonly connection cannot start a transaction.')
|
|
147
149
|
}
|
|
148
150
|
|
|
149
151
|
if (this.isTransaction()) {
|
|
150
|
-
|
|
152
|
+
throw new Error('Connection is already in a transaction.');
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
this.$transaction = true;
|
|
154
156
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
+
}
|