@breautek/storm 9.2.0 → 9.2.2
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 +14 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Application.html +17 -17
- package/docs/classes/ConfigLoader.html +3 -3
- package/docs/classes/Database.html +2 -2
- package/docs/classes/DatabaseCastObject.html +2 -2
- package/docs/classes/DatabaseConnection.html +21 -21
- package/docs/classes/DatabaseQueryError.html +6 -6
- package/docs/classes/DeadLockError.html +6 -6
- package/docs/classes/DiskSpaceError.html +5 -5
- package/docs/classes/DropTemporaryTableQuery.html +7 -7
- package/docs/classes/DuplicateEntryError.html +5 -5
- package/docs/classes/EntityNotFoundError.html +5 -5
- package/docs/classes/ExpiredTokenError.html +5 -5
- package/docs/classes/GetMySQLVersion.html +25 -0
- package/docs/classes/Handler.html +2 -2
- package/docs/classes/IllegalStateError.html +5 -5
- package/docs/classes/InternalError.html +5 -5
- package/docs/classes/InvalidCredentialsError.html +5 -5
- package/docs/classes/InvalidValueError.html +5 -5
- package/docs/classes/LineString.html +2 -2
- package/docs/classes/LockWaitTimeoutError.html +6 -6
- package/docs/classes/ManagedDatabaseConnection.html +5 -5
- package/docs/classes/Middleware.html +2 -2
- package/docs/classes/MissingConfigError.html +5 -5
- package/docs/classes/MissingParameterError.html +5 -5
- package/docs/classes/MySQLConnection.html +26 -25
- package/docs/classes/MySQLDatabase.html +2 -2
- package/docs/classes/NotImplementedError.html +5 -5
- package/docs/classes/Point.html +2 -2
- package/docs/classes/Polygon.html +2 -2
- package/docs/classes/Query.html +7 -7
- package/docs/classes/RawError.html +5 -5
- package/docs/classes/RawQuery.html +7 -7
- package/docs/classes/Request.html +3 -3
- package/docs/classes/Response.html +2 -2
- package/docs/classes/ResponseData.html +3 -3
- package/docs/classes/ServiceProvider.html +2 -2
- package/docs/classes/ServiceResponse.html +2 -2
- package/docs/classes/SetSessionVariableQuery.html +7 -7
- package/docs/classes/StormError.html +5 -5
- package/docs/classes/TemporaryTableQuery.html +7 -7
- package/docs/classes/TimeoutError.html +5 -5
- package/docs/classes/Token.html +2 -2
- package/docs/classes/TokenManager.html +2 -2
- package/docs/classes/Transaction.html +2 -2
- package/docs/classes/UnauthorizedAccessError.html +5 -5
- package/docs/enums/ErrorCode.html +2 -2
- package/docs/enums/ExitCode.html +2 -2
- package/docs/enums/HTTPMethod.html +2 -2
- package/docs/enums/IsolationLevel.html +2 -2
- package/docs/enums/JWTError.html +2 -2
- package/docs/enums/StatusCode.html +2 -2
- package/docs/enums/TransactionAccessLevel.html +2 -2
- package/docs/functions/getInstance.html +1 -1
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +1 -1
- package/docs/interfaces/IAdditionalErrorDetails.html +1 -1
- package/docs/interfaces/ICloudwatchConfig.html +2 -2
- package/docs/interfaces/ICloudwatchCredentials.html +2 -2
- package/docs/interfaces/ICloudwatchStreamConfig.html +2 -2
- package/docs/interfaces/IConfig.html +15 -2
- package/docs/interfaces/IDatabaseConfig.html +2 -2
- package/docs/interfaces/IDatabaseConnection.html +5 -5
- package/docs/interfaces/IDatabasePosition.html +2 -2
- package/docs/interfaces/IErrorResponse.html +2 -2
- package/docs/interfaces/IFormData.html +2 -2
- package/docs/interfaces/IGetMySQLVersionResult.html +5 -0
- package/docs/interfaces/IGetMySQLVersionRow.html +2 -0
- package/docs/interfaces/IInsertQueryResult.html +2 -2
- package/docs/interfaces/IJWTVerifyOptions.html +2 -2
- package/docs/interfaces/IOKPacket.html +2 -2
- package/docs/interfaces/IParameterMap.html +1 -1
- package/docs/interfaces/IQueryable.html +2 -2
- package/docs/interfaces/IRequestResponse.html +2 -2
- package/docs/interfaces/ISetSessionVariableQueryInput.html +2 -2
- package/docs/interfaces/IStormCLIArgs.html +2 -2
- package/docs/interfaces/ITemporaryTableQueryInput.html +2 -2
- package/docs/interfaces/IUpdateQueryResult.html +2 -2
- package/docs/interfaces/formidable.FileJSON.html +1 -1
- package/docs/interfaces/formidable.Part.html +1 -1
- package/docs/types/IDeleteQueryResult.html +1 -1
- package/docs/types/IStoredProcedureResult.html +1 -1
- package/docs/types/TCoordinate.html +1 -1
- package/docs/types/TExpiresIn.html +1 -1
- package/docs/types/TSerializableResponse.html +1 -1
- package/docs/types/TSupportedResponsePrimitives.html +1 -1
- package/docs/types/TSupportedResponseTypes.html +1 -1
- package/jest.config.js +1 -0
- package/lib/ConfigLoader.js +1 -0
- package/lib/ConfigLoader.js.map +1 -1
- package/lib/GetMySQLVersion.d.ts +15 -0
- package/lib/GetMySQLVersion.js +28 -0
- package/lib/GetMySQLVersion.js.map +1 -0
- package/lib/IConfig.d.ts +16 -0
- package/lib/MySQLConnection.d.ts +3 -0
- package/lib/MySQLConnection.js +42 -12
- package/lib/MySQLConnection.js.map +1 -1
- package/lib/api.d.ts +1 -0
- package/lib/api.js +4 -2
- package/lib/api.js.map +1 -1
- package/lib/mysql/queryFormatter.d.ts +11 -0
- package/lib/mysql/queryFormatter.js +11 -0
- package/lib/mysql/queryFormatter.js.map +1 -1
- package/lib/private/GetMasterPositionQuery.d.ts +4 -0
- package/lib/private/GetMasterPositionQuery.js +4 -0
- package/lib/private/GetMasterPositionQuery.js.map +1 -1
- package/lib/private/GetPrimaryPositionQuery.d.ts +14 -0
- package/lib/private/GetPrimaryPositionQuery.js +35 -0
- package/lib/private/GetPrimaryPositionQuery.js.map +1 -0
- package/package.json +1 -1
- package/src/ConfigLoader.ts +1 -0
- package/src/GetMySQLVersion.ts +41 -0
- package/src/IConfig.ts +17 -0
- package/src/MySQLConnection.ts +55 -15
- package/src/api.ts +1 -0
- package/src/mysql/queryFormatter.ts +11 -0
- package/src/private/GetMasterPositionQuery.ts +4 -0
- package/src/private/GetPrimaryPositionQuery.ts +40 -0
package/src/MySQLConnection.ts
CHANGED
|
@@ -37,6 +37,8 @@ import { GetMasterPositionQuery } from './private/GetMasterPositionQuery';
|
|
|
37
37
|
import { IQueryable } from './IQueryable';
|
|
38
38
|
import { TransactionAccessLevel } from './TransactionAccessLevel';
|
|
39
39
|
import { GetProcessList, IGetProcessListOutput } from './private/GetProcessList';
|
|
40
|
+
import { GetMySQLVersion, IGetMySQLVersionResult } from './GetMySQLVersion';
|
|
41
|
+
import { GetPrimaryPositionQuery } from './private/GetPrimaryPositionQuery';
|
|
40
42
|
|
|
41
43
|
const DEFAULT_HIGH_WATERMARK: number = 512; // in number of result objects
|
|
42
44
|
const TAG: string = 'MySQLConnection';
|
|
@@ -64,29 +66,47 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
|
|
|
64
66
|
private $opened: boolean;
|
|
65
67
|
private $hasReplicationEnabled: boolean;
|
|
66
68
|
private $isMasterConnection: boolean;
|
|
69
|
+
private $version: IGetMySQLVersionResult;
|
|
67
70
|
|
|
68
71
|
public constructor(connection: MySQL.PoolConnection, instantiationStack: string, isReadOnly: boolean = true) {
|
|
69
72
|
connection.config.namedPlaceholders = true;
|
|
73
|
+
|
|
74
|
+
if (!getInstance().getConfig().enableMySQL2BreakingChanges) {
|
|
75
|
+
connection.config.typeCast = function (field: MySQL.TypeCastField, next: MySQL.TypeCastNext): any {
|
|
76
|
+
// TODO: Expose a setting to opt out of these backwards-compatibility type casting
|
|
77
|
+
// So we can have a chance of a rolling refactor.
|
|
78
|
+
if (
|
|
79
|
+
[
|
|
80
|
+
'DECIMAL',
|
|
81
|
+
'NEWDECIMAL',
|
|
82
|
+
'DOUBLE'
|
|
83
|
+
].indexOf(field.type) > -1
|
|
84
|
+
) {
|
|
85
|
+
let parsed: number = parseFloat(field.string());
|
|
86
|
+
if (isNaN(parsed)) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return parsed;
|
|
90
|
+
}
|
|
91
|
+
else if (
|
|
92
|
+
([
|
|
93
|
+
'JSON'
|
|
94
|
+
]).indexOf(field.type) > -1
|
|
95
|
+
) {
|
|
96
|
+
return field.string();
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return next();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
|
|
70
104
|
super(connection, isReadOnly, instantiationStack);
|
|
71
105
|
|
|
72
106
|
this.$hasReplicationEnabled = false;
|
|
73
107
|
this.$opened = true;
|
|
74
108
|
this.$transaction = false;
|
|
75
109
|
this.$isMasterConnection = null;
|
|
76
|
-
|
|
77
|
-
// connection.config.queryFormat = queryFormatter.bind(this);
|
|
78
|
-
|
|
79
|
-
// connection.config.queryFormat = function(query: string, values: any) {
|
|
80
|
-
// if (!values) return query;
|
|
81
|
-
|
|
82
|
-
// return query.replace(/:(\w+)/g, function(this: any, txt: string, key: string): string {
|
|
83
|
-
// // eslint-disable-next-line no-prototype-builtins
|
|
84
|
-
// if (values.hasOwnProperty(key)) {
|
|
85
|
-
// return this.escape(values[key]);
|
|
86
|
-
// }
|
|
87
|
-
// return txt;
|
|
88
|
-
// }.bind(this));
|
|
89
|
-
// };
|
|
90
110
|
}
|
|
91
111
|
|
|
92
112
|
/**
|
|
@@ -113,6 +133,14 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
|
|
|
113
133
|
}
|
|
114
134
|
}
|
|
115
135
|
|
|
136
|
+
public async getVersion(): Promise<IGetMySQLVersionResult> {
|
|
137
|
+
if (!this.$version) {
|
|
138
|
+
this.$version = await new GetMySQLVersion().execute(this);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return {...this.$version};
|
|
142
|
+
}
|
|
143
|
+
|
|
116
144
|
public override formatQuery(query: IQueryable<any>): string {
|
|
117
145
|
return this.getAPI().format(query.getQuery(this), query.getParametersForQuery());
|
|
118
146
|
}
|
|
@@ -148,7 +176,19 @@ export class MySQLConnection extends DatabaseConnection<MySQL.PoolConnection> {
|
|
|
148
176
|
}
|
|
149
177
|
|
|
150
178
|
public override async getCurrentDatabasePosition(): Promise<IDatabasePosition> {
|
|
151
|
-
let
|
|
179
|
+
let version: IGetMySQLVersionResult = await this.getVersion();
|
|
180
|
+
let statusQuery: GetBinLogPositionQuery = null;
|
|
181
|
+
|
|
182
|
+
if (
|
|
183
|
+
(version.major === 8 && version.minor >= 4) || version.major >= 9
|
|
184
|
+
) {
|
|
185
|
+
// >= 8.4 we need to use a different setof master/slave queries
|
|
186
|
+
statusQuery = this.isReplication() ? new GetSlavePositionQuery() : new GetPrimaryPositionQuery();
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
statusQuery = this.isReplication() ? new GetSlavePositionQuery() : new GetMasterPositionQuery();
|
|
190
|
+
}
|
|
191
|
+
|
|
152
192
|
return await statusQuery.execute(this);
|
|
153
193
|
}
|
|
154
194
|
|
package/src/api.ts
CHANGED
|
@@ -43,6 +43,7 @@ export {Transaction} from './Transaction';
|
|
|
43
43
|
export {IOKPacket} from './IOKPacket';
|
|
44
44
|
export {IStoredProcedureResult} from './IStoredProcedureResult';
|
|
45
45
|
export {TransactionAccessLevel} from './TransactionAccessLevel';
|
|
46
|
+
export {GetMySQLVersion, IGetMySQLVersionResult, IGetMySQLVersionRow} from './GetMySQLVersion';
|
|
46
47
|
|
|
47
48
|
// Errors
|
|
48
49
|
export {ErrorCode} from './ErrorCode';
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
|
|
2
2
|
import * as MySQL from 'mysql2';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Formats a query by resolving named parameters.
|
|
6
|
+
*
|
|
7
|
+
* With older `mysql` driver, this was used to facilitate actual named parameters.
|
|
8
|
+
* @since 9.2.0 - this is now only used for logging/debugging purposes, as `mysql2`
|
|
9
|
+
* driver has built-in named parameter support.
|
|
10
|
+
*
|
|
11
|
+
* @param query
|
|
12
|
+
* @param values
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
4
15
|
export function queryFormatter(query: string, values: any): string {
|
|
5
16
|
if (!values) return query;
|
|
6
17
|
|
|
@@ -21,6 +21,10 @@ interface IStatus {
|
|
|
21
21
|
Position: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* For use with MySQL 8.0 and earlier. Obsolete since MySQL 8.4
|
|
26
|
+
* @deprecated
|
|
27
|
+
*/
|
|
24
28
|
export class GetMasterPositionQuery extends GetBinLogPositionQuery<IStatus> {
|
|
25
29
|
|
|
26
30
|
protected override _getQuery(): string {
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2017-2024 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 { GetBinLogPositionQuery } from './GetBinLogPositionQuery';
|
|
18
|
+
|
|
19
|
+
interface IStatus {
|
|
20
|
+
File: string;
|
|
21
|
+
Position: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* For use with MySQL 8.4 and later
|
|
26
|
+
*/
|
|
27
|
+
export class GetPrimaryPositionQuery extends GetBinLogPositionQuery<IStatus> {
|
|
28
|
+
|
|
29
|
+
protected override _getQuery(): string {
|
|
30
|
+
return 'SHOW BINARY LOG STATUS';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected override _getFile(row: IStatus): string {
|
|
34
|
+
return row.File;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
protected override _getPosition(row: IStatus): string {
|
|
38
|
+
return row.Position;
|
|
39
|
+
}
|
|
40
|
+
}
|