@bitblit/ratchet-rdbms 6.0.145-alpha → 6.0.147-alpha
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/lib/rds-data-api/model/rds-data-api-connection-config.d.ts +2 -0
- package/lib/rds-data-api/rds-data-api-database-access.d.ts +3 -0
- package/lib/rds-data-api/rds-data-api-database-access.js +35 -4
- package/lib/rds-data-api/rds-data-api-database-access.js.map +1 -1
- package/package.json +4 -3
- package/src/build/ratchet-rdbms-info.ts +19 -0
- package/src/model/connection-and-tunnel.ts +7 -0
- package/src/model/database-access-provider.ts +11 -0
- package/src/model/database-access.ts +30 -0
- package/src/model/database-config-list.ts +3 -0
- package/src/model/database-request-type.ts +6 -0
- package/src/model/group-by-count-result.ts +4 -0
- package/src/model/modify-results.ts +9 -0
- package/src/model/named-parameter-database-service-config.ts +13 -0
- package/src/model/paginated-results.ts +5 -0
- package/src/model/pagination-bounds.ts +12 -0
- package/src/model/paginator.ts +20 -0
- package/src/model/query-defaults.ts +4 -0
- package/src/model/query-text-provider.ts +4 -0
- package/src/model/request-results.ts +4 -0
- package/src/model/simple-query-text-provider.ts +18 -0
- package/src/model/sort-direction.ts +4 -0
- package/src/model/ssh/ssh-tunnel-config.ts +8 -0
- package/src/model/ssh/ssh-tunnel-container.ts +13 -0
- package/src/model/transaction-isolation-level.ts +4 -0
- package/src/mysql/model/mysql-db-config.ts +14 -0
- package/src/mysql/model/mysql-master-status.ts +6 -0
- package/src/mysql/model/mysql-slave-status.ts +52 -0
- package/src/mysql/mysql-style-database-access.ts +85 -0
- package/src/mysql/rds-mysql-style-connection-provider.ts +265 -0
- package/src/postgres/model/postgres-db-config.ts +8 -0
- package/src/postgres/postgres-style-connection-provider.ts +270 -0
- package/src/postgres/postgres-style-database-access.spec.ts +76 -0
- package/src/postgres/postgres-style-database-access.ts +110 -0
- package/src/query-builder/query-builder-result.ts +21 -0
- package/src/query-builder/query-builder.spec.ts +194 -0
- package/src/query-builder/query-builder.ts +445 -0
- package/src/query-builder/query-util.spec.ts +20 -0
- package/src/query-builder/query-util.ts +162 -0
- package/src/rds-data-api/model/rds-data-api-connection-config.ts +8 -0
- package/src/rds-data-api/rds-data-api-connection-provider.ts +39 -0
- package/src/rds-data-api/rds-data-api-database-access.spec.ts +139 -0
- package/src/rds-data-api/rds-data-api-database-access.ts +209 -0
- package/src/service/named-parameter-database-service.ts +421 -0
- package/src/service/ssh-tunnel-service.ts +62 -0
- package/src/service/transactional-named-parameter-database-service.ts +171 -0
- package/src/sqlite/model/fetch-remote-mode.ts +4 -0
- package/src/sqlite/model/flush-remote-mode.ts +4 -0
- package/src/sqlite/model/sqlite-connection-config-flag.ts +3 -0
- package/src/sqlite/model/sqlite-connection-config.ts +11 -0
- package/src/sqlite/model/sqlite-local-file-config.ts +3 -0
- package/src/sqlite/model/sqlite-remote-file-sync-config.ts +9 -0
- package/src/sqlite/sqlite-database-access.spec.ts +158 -0
- package/src/sqlite/sqlite-database-access.ts +126 -0
- package/src/sqlite/sqlite-remote-sync-database-access.ts +152 -0
- package/src/sqlite/sqlite-style-connection-provider.ts +181 -0
- package/src/util/aws-rds-cert-2023.ts +502 -0
- package/src/util/named-parameter-adapter/named-parameter-adapter.ts +51 -0
- package/src/util/named-parameter-adapter/query-and-params.ts +4 -0
- package/src/util/relational-database-utils.ts +54 -0
|
@@ -8,6 +8,9 @@ export declare class RdsDataApiDatabaseAccess implements DatabaseAccess {
|
|
|
8
8
|
private cfg;
|
|
9
9
|
private _currentTransactionId;
|
|
10
10
|
constructor(client: RDSDataClient, cfg: RdsDataApiConnectionConfig);
|
|
11
|
+
private get maxWaitForResumingDatabase();
|
|
12
|
+
private get dbResumePingTimeMillis();
|
|
13
|
+
sendWithDatabaseWait(cmd: any): Promise<any>;
|
|
11
14
|
beginTransaction(): Promise<void>;
|
|
12
15
|
close(): Promise<boolean>;
|
|
13
16
|
commitTransaction(): Promise<void>;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { BeginTransactionCommand, CommitTransactionCommand, ExecuteStatementCommand, RollbackTransactionCommand } from "@aws-sdk/client-rds-data";
|
|
1
|
+
import { BeginTransactionCommand, CommitTransactionCommand, DatabaseResumingException, ExecuteStatementCommand, RollbackTransactionCommand } from "@aws-sdk/client-rds-data";
|
|
2
2
|
import { Logger } from "@bitblit/ratchet-common/logger/logger";
|
|
3
3
|
import SqlString from 'sqlstring';
|
|
4
|
+
import { PromiseRatchet } from "@bitblit/ratchet-common/lang/promise-ratchet";
|
|
5
|
+
import { ErrorRatchet } from "@bitblit/ratchet-common/lang/error-ratchet";
|
|
4
6
|
export class RdsDataApiDatabaseAccess {
|
|
5
7
|
client;
|
|
6
8
|
cfg;
|
|
@@ -9,8 +11,37 @@ export class RdsDataApiDatabaseAccess {
|
|
|
9
11
|
this.client = client;
|
|
10
12
|
this.cfg = cfg;
|
|
11
13
|
}
|
|
14
|
+
get maxWaitForResumingDatabase() {
|
|
15
|
+
return this?.cfg?.maximumWaitForDbResumeInMillis ?? 0;
|
|
16
|
+
}
|
|
17
|
+
get dbResumePingTimeMillis() {
|
|
18
|
+
return this?.cfg?.dbResumePingTimeMillis ?? 1_000;
|
|
19
|
+
}
|
|
20
|
+
async sendWithDatabaseWait(cmd) {
|
|
21
|
+
const startTime = Date.now();
|
|
22
|
+
let rval;
|
|
23
|
+
do {
|
|
24
|
+
try {
|
|
25
|
+
rval = await this.client.send(cmd);
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
if (err instanceof DatabaseResumingException) {
|
|
29
|
+
Logger.debug('Database was resuming - waiting %d ms before retry : %s', this.dbResumePingTimeMillis, err);
|
|
30
|
+
await PromiseRatchet.wait(this.dbResumePingTimeMillis);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
throw err;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} while (!rval && Date.now() - startTime < this.maxWaitForResumingDatabase);
|
|
37
|
+
if (!rval) {
|
|
38
|
+
Logger.error('Timed out waiting for db to start');
|
|
39
|
+
throw ErrorRatchet.fErr('Timed out waiting for db to start');
|
|
40
|
+
}
|
|
41
|
+
return rval;
|
|
42
|
+
}
|
|
12
43
|
async beginTransaction() {
|
|
13
|
-
const tmp = await this.
|
|
44
|
+
const tmp = await this.sendWithDatabaseWait(new BeginTransactionCommand({ resourceArn: this.cfg.resourceArn, secretArn: this.cfg.secretArn }));
|
|
14
45
|
this._currentTransactionId = tmp.transactionId;
|
|
15
46
|
Logger.info('Started transaction %s', this._currentTransactionId);
|
|
16
47
|
}
|
|
@@ -23,7 +54,7 @@ export class RdsDataApiDatabaseAccess {
|
|
|
23
54
|
}
|
|
24
55
|
async commitTransaction() {
|
|
25
56
|
if (this._currentTransactionId) {
|
|
26
|
-
const out = await this.
|
|
57
|
+
const out = await this.sendWithDatabaseWait(new CommitTransactionCommand({ resourceArn: this.cfg.resourceArn, secretArn: this.cfg.secretArn, transactionId: this._currentTransactionId }));
|
|
27
58
|
Logger.info('Commit transaction %s returned %j', this._currentTransactionId, out);
|
|
28
59
|
this._currentTransactionId = null;
|
|
29
60
|
}
|
|
@@ -37,7 +68,7 @@ export class RdsDataApiDatabaseAccess {
|
|
|
37
68
|
}
|
|
38
69
|
async modify(query, fields) {
|
|
39
70
|
const params = RdsDataApiDatabaseAccess.toSqlParameters(fields);
|
|
40
|
-
const tmp = await this.
|
|
71
|
+
const tmp = await this.sendWithDatabaseWait(new ExecuteStatementCommand({ resourceArn: this.cfg.resourceArn, secretArn: this.cfg.secretArn, database: this.cfg.database, sql: query, parameters: params, includeResultMetadata: true }));
|
|
41
72
|
const rval = {
|
|
42
73
|
results: {
|
|
43
74
|
changedRows: tmp.numberOfRecordsUpdated,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rds-data-api-database-access.js","sourceRoot":"","sources":["../../src/rds-data-api/rds-data-api-database-access.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,uBAAuB,EAEvB,wBAAwB,
|
|
1
|
+
{"version":3,"file":"rds-data-api-database-access.js","sourceRoot":"","sources":["../../src/rds-data-api/rds-data-api-database-access.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,uBAAuB,EAEvB,wBAAwB,EACxB,yBAAyB,EAAE,uBAAuB,EAEnC,0BAA0B,EAC1C,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAE/D,OAAO,SAAS,MAAM,WAAW,CAAC;AAGlC,OAAO,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAE1E,MAAM,OAAO,wBAAwB;IAKzB;IACA;IAJF,qBAAqB,CAAS;IAEtC,YACU,MAAqB,EACrB,GAA+B;QAD/B,WAAM,GAAN,MAAM,CAAe;QACrB,QAAG,GAAH,GAAG,CAA4B;IACtC,CAAC;IAEJ,IAAY,0BAA0B;QACpC,OAAO,IAAI,EAAE,GAAG,EAAE,8BAA8B,IAAI,CAAC,CAAC;IACxD,CAAC;IAED,IAAY,sBAAsB;QAChC,OAAO,IAAI,EAAE,GAAG,EAAE,sBAAsB,IAAI,KAAK,CAAC;IACpD,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,GAAQ;QACxC,MAAM,SAAS,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;QACrC,IAAI,IAAS,CAAC;QACd,GAAG,CAAC;YACF,IAAI,CAAC;gBACH,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACrC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,IAAI,GAAG,YAAY,yBAAyB,EAAE,CAAC;oBAC7C,MAAM,CAAC,KAAK,CAAC,yDAAyD,EAAE,IAAI,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC;oBAC1G,MAAM,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC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O,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACvF,OAAO,IAAI,CAAC;IACd,CAAC;CAqBF"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bitblit/ratchet-rdbms",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.147-alpha",
|
|
4
4
|
"description": "Ratchet tooling for working with relational databases",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"files": [
|
|
8
|
+
"src/**",
|
|
8
9
|
"lib/**",
|
|
9
10
|
"bin/**"
|
|
10
11
|
],
|
|
@@ -47,7 +48,7 @@
|
|
|
47
48
|
},
|
|
48
49
|
"license": "Apache-2.0",
|
|
49
50
|
"dependencies": {
|
|
50
|
-
"@bitblit/ratchet-common": "6.0.
|
|
51
|
+
"@bitblit/ratchet-common": "6.0.147-alpha"
|
|
51
52
|
},
|
|
52
53
|
"optionalDependencies": {
|
|
53
54
|
"@aws-sdk/client-rds-data": "3.922.0",
|
|
@@ -60,7 +61,7 @@
|
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|
|
62
63
|
"@aws-sdk/client-rds-data": "^3.922.0",
|
|
63
|
-
"@bitblit/ratchet-common": "6.0.
|
|
64
|
+
"@bitblit/ratchet-common": "6.0.147-alpha",
|
|
64
65
|
"better-sqlite3": "^12.4.1",
|
|
65
66
|
"get-port": "^7.1.0",
|
|
66
67
|
"mysql2": "^3.15.3",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BuildInformation } from '@bitblit/ratchet-common/build/build-information';
|
|
2
|
+
|
|
3
|
+
export class RatchetRdbmsInfo {
|
|
4
|
+
// Empty constructor prevents instantiation
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
6
|
+
private constructor() {}
|
|
7
|
+
|
|
8
|
+
public static buildInformation(): BuildInformation {
|
|
9
|
+
const val: BuildInformation = {
|
|
10
|
+
version: 'LOCAL-SNAPSHOT',
|
|
11
|
+
hash: 'LOCAL-HASH',
|
|
12
|
+
branch: 'LOCAL-BRANCH',
|
|
13
|
+
tag: 'LOCAL-TAG',
|
|
14
|
+
timeBuiltISO: 'LOCAL-TIME-ISO',
|
|
15
|
+
notes: 'LOCAL-NOTES',
|
|
16
|
+
};
|
|
17
|
+
return val;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { DatabaseAccess } from './database-access.js';
|
|
2
|
+
import { QueryDefaults } from './query-defaults.js';
|
|
3
|
+
|
|
4
|
+
export interface DatabaseAccessProvider {
|
|
5
|
+
/**
|
|
6
|
+
* @param name if omitted, returns the default connection
|
|
7
|
+
*/
|
|
8
|
+
getDatabaseAccess(name?: string): Promise<DatabaseAccess | undefined>;
|
|
9
|
+
clearDatabaseAccessCache(): Promise<boolean>;
|
|
10
|
+
createNonPooledDatabaseAccess?(queryDefaults: QueryDefaults, additionalConfig?: Record<string, any>): Promise<DatabaseAccess | undefined>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Represents the object used to actually talk to the database, such
|
|
2
|
+
// as a Connection object in mysql/maria, an HTTP wrapper for an HTTP db,
|
|
3
|
+
// or a AsyncDatabase object in sqlite. Usually it'll be a wrapper around
|
|
4
|
+
// the actual object to act as an adapter
|
|
5
|
+
import { RequestResults } from './request-results.js';
|
|
6
|
+
import { ModifyResults } from './modify-results.js';
|
|
7
|
+
import { DatabaseRequestType } from './database-request-type.js';
|
|
8
|
+
|
|
9
|
+
// T = Class of the connection
|
|
10
|
+
// R = Class of any extra connection configuration props
|
|
11
|
+
// S = Class of the object returned by a query (data)
|
|
12
|
+
export interface DatabaseAccess {
|
|
13
|
+
// Force the connection closed
|
|
14
|
+
close(): Promise<boolean>;
|
|
15
|
+
escape(value: any): string;
|
|
16
|
+
|
|
17
|
+
testConnection(logTestResults?: boolean): Promise<number>; // Should be a fast test like 'select 1'
|
|
18
|
+
|
|
19
|
+
preQuery?(): Promise<void>;
|
|
20
|
+
query<S>(query: string, fields: Record<string, any>): Promise<RequestResults<S>>;
|
|
21
|
+
modify(query: string, fields: Record<string, any>): Promise<RequestResults<ModifyResults>>;
|
|
22
|
+
// TODO: Handle DDL specially?
|
|
23
|
+
onRequestSuccessOnly?(type: DatabaseRequestType): Promise<void>;
|
|
24
|
+
onRequestFailureOnly?(type: DatabaseRequestType): Promise<void>;
|
|
25
|
+
onRequestSuccessOrFailure?(type: DatabaseRequestType): Promise<void>;
|
|
26
|
+
|
|
27
|
+
beginTransaction?(): Promise<void>;
|
|
28
|
+
commitTransaction?(): Promise<void>;
|
|
29
|
+
rollbackTransaction?(): Promise<void>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { QueryTextProvider } from './query-text-provider.js';
|
|
2
|
+
import { DatabaseAccessProvider } from './database-access-provider.js';
|
|
3
|
+
import { QueryDefaults } from './query-defaults.js';
|
|
4
|
+
import { LoggerInstance } from '@bitblit/ratchet-common/logger/logger-instance';
|
|
5
|
+
|
|
6
|
+
export interface NamedParameterDatabaseServiceConfig {
|
|
7
|
+
serviceName: string;
|
|
8
|
+
queryProvider: QueryTextProvider;
|
|
9
|
+
connectionProvider: DatabaseAccessProvider;
|
|
10
|
+
queryDefaults: QueryDefaults;
|
|
11
|
+
longQueryTimeMs: number;
|
|
12
|
+
logger?: LoggerInstance;
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the bounds of a paginator.
|
|
3
|
+
*
|
|
4
|
+
* Returns the min and max values for the column specified and the total count - can
|
|
5
|
+
* be used to roughly predict page values
|
|
6
|
+
*/
|
|
7
|
+
export interface PaginationBounds<T> {
|
|
8
|
+
cn: string;
|
|
9
|
+
min: T;
|
|
10
|
+
max: T;
|
|
11
|
+
count: number;
|
|
12
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { SortDirection } from './sort-direction.js';
|
|
2
|
+
import { JwtTokenBase } from '@bitblit/ratchet-common/jwt/jwt-token-base';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Defines a paginator.
|
|
6
|
+
*
|
|
7
|
+
* Field names are short in here because this gets serialized when passed back and forth. They are:
|
|
8
|
+
* cn: ColumnName (required)
|
|
9
|
+
* min: min value for that column (optional)
|
|
10
|
+
* max: max value for that column (optional)
|
|
11
|
+
* s: sort direction for the column (optional, defaults to Asc)
|
|
12
|
+
* l: limit (optional)
|
|
13
|
+
*/
|
|
14
|
+
export interface Paginator<T> extends JwtTokenBase {
|
|
15
|
+
cn: string;
|
|
16
|
+
min?: T;
|
|
17
|
+
max?: T;
|
|
18
|
+
s?: SortDirection;
|
|
19
|
+
l?: number;
|
|
20
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { QueryTextProvider } from './query-text-provider.js';
|
|
2
|
+
import { StringRatchet } from '@bitblit/ratchet-common/lang/string-ratchet';
|
|
3
|
+
|
|
4
|
+
export class SimpleQueryTextProvider implements QueryTextProvider {
|
|
5
|
+
constructor(private values: Record<string, string>) {}
|
|
6
|
+
|
|
7
|
+
public fetchQuery(queryDottedPath: string): string {
|
|
8
|
+
let rval: string = null;
|
|
9
|
+
if (StringRatchet.trimToNull(queryDottedPath)) {
|
|
10
|
+
rval = (this.values ?? {})[queryDottedPath];
|
|
11
|
+
}
|
|
12
|
+
return rval;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public fetchAllQueries(): Record<string, string> {
|
|
16
|
+
return Object.assign({}, this.values ?? {});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ListenOptions, Server } from 'net';
|
|
2
|
+
import type { ConnectConfig, Connection } from 'ssh2';
|
|
3
|
+
import * as TunnelSsh from 'tunnel-ssh';
|
|
4
|
+
|
|
5
|
+
export interface SshTunnelContainer {
|
|
6
|
+
tunnelOptions: TunnelSsh.TunnelOptions;
|
|
7
|
+
serverOptions: ListenOptions;
|
|
8
|
+
sshOptions: ConnectConfig;
|
|
9
|
+
forwardOptions: TunnelSsh.ForwardOptions;
|
|
10
|
+
server: Server;
|
|
11
|
+
localPort: number;
|
|
12
|
+
connection?: Connection;
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { SshTunnelConfig } from '../../model/ssh/ssh-tunnel-config.js';
|
|
2
|
+
|
|
3
|
+
export interface MysqlDbConfig {
|
|
4
|
+
label: string;
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
user: string;
|
|
8
|
+
password: string;
|
|
9
|
+
database: string;
|
|
10
|
+
sshTunnelConfig?: SshTunnelConfig;
|
|
11
|
+
|
|
12
|
+
ssl?: string | Record<string, any>;
|
|
13
|
+
decimalNumbers?: boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface MysqlSlaveStatus {
|
|
2
|
+
Slave_IO_State: string;
|
|
3
|
+
Master_Host: string;
|
|
4
|
+
Master_User: string;
|
|
5
|
+
Master_Port: number;
|
|
6
|
+
Connect_Retry: number;
|
|
7
|
+
Master_Log_File: string;
|
|
8
|
+
Read_Master_Log_Pos: number;
|
|
9
|
+
Relay_Log_File: string;
|
|
10
|
+
Relay_Log_Pos: number;
|
|
11
|
+
Relay_Master_Log_File: string;
|
|
12
|
+
Slave_IO_Running: string;
|
|
13
|
+
Slave_SQL_Running: string;
|
|
14
|
+
Replicate_Do_DB: string;
|
|
15
|
+
Replicate_Ignore_DB: string;
|
|
16
|
+
Replicate_Do_Table: string;
|
|
17
|
+
Replicate_Ignore_Table: string;
|
|
18
|
+
Replicate_Wild_Do_Table: string;
|
|
19
|
+
Replicate_Wild_Ignore_Table: string;
|
|
20
|
+
Last_Errno: number;
|
|
21
|
+
Last_Error: string;
|
|
22
|
+
Skip_Counter: number;
|
|
23
|
+
Exec_Master_Log_Pos: number;
|
|
24
|
+
Relay_Log_Space: number;
|
|
25
|
+
Until_Condition: string;
|
|
26
|
+
Until_Log_File: string;
|
|
27
|
+
Until_Log_Pos: number;
|
|
28
|
+
Master_SSL_Allowed: string;
|
|
29
|
+
Master_SSL_CA_File: string;
|
|
30
|
+
Master_SSL_CA_Path: string;
|
|
31
|
+
Master_SSL_Cert: string;
|
|
32
|
+
Master_SSL_Cipher: string;
|
|
33
|
+
Master_SSL_Key: string;
|
|
34
|
+
Seconds_Behind_Master: number;
|
|
35
|
+
Master_SSL_Verify_Server_Cert: string;
|
|
36
|
+
Last_IO_Errno: number;
|
|
37
|
+
Last_IO_Error: string;
|
|
38
|
+
Last_SQL_Errno: number;
|
|
39
|
+
Last_SQL_Error: string;
|
|
40
|
+
Replicate_Ignore_Server_Ids: string;
|
|
41
|
+
Master_Server_Id: number;
|
|
42
|
+
Master_SSL_Crl: string;
|
|
43
|
+
Master_SSL_Crlpath: string;
|
|
44
|
+
Using_Gtid: string;
|
|
45
|
+
Gtid_IO_Pos: string;
|
|
46
|
+
Replicate_Do_Domain_Ids: string;
|
|
47
|
+
Replicate_Ignore_Domain_Ids: string;
|
|
48
|
+
Parallel_Mode: string;
|
|
49
|
+
SQL_Delay: number;
|
|
50
|
+
SQL_Remaining_Delay: string;
|
|
51
|
+
Slave_SQL_Running_State: string;
|
|
52
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Connection, ConnectionOptions, FieldPacket, RowDataPacket } from 'mysql2/promise';
|
|
2
|
+
import { DatabaseAccess } from '../model/database-access.js';
|
|
3
|
+
import { RequestResults } from '../model/request-results.js';
|
|
4
|
+
import { ModifyResults } from '../model/modify-results.js';
|
|
5
|
+
import { DatabaseRequestType } from '../model/database-request-type.js';
|
|
6
|
+
import { Logger } from '@bitblit/ratchet-common/logger/logger';
|
|
7
|
+
|
|
8
|
+
export class MysqlStyleDatabaseAccess implements DatabaseAccess {
|
|
9
|
+
constructor(
|
|
10
|
+
private _connection: Connection,
|
|
11
|
+
private _connectionOptions: ConnectionOptions,
|
|
12
|
+
) {}
|
|
13
|
+
|
|
14
|
+
public async testConnection(logTestResults?: boolean): Promise<number | null> {
|
|
15
|
+
if (logTestResults) {
|
|
16
|
+
Logger.info('Running connection test');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const res: RequestResults<any> = await this.query('SELECT UNIX_TIMESTAMP(now())*1000 AS test', {});
|
|
20
|
+
const rows = res.results as { test: number }[];
|
|
21
|
+
const timestamp = rows.length === 1 ? rows[0].test : null;
|
|
22
|
+
if (logTestResults) {
|
|
23
|
+
Logger.info('Test returned : %j', timestamp);
|
|
24
|
+
}
|
|
25
|
+
return timestamp;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public getRawDatabase(): Connection {
|
|
29
|
+
return this._connection;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public getRawDatabaseConfig(): ConnectionOptions {
|
|
33
|
+
return this._connectionOptions;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public testConnectionQueryString(): string {
|
|
37
|
+
return 'SELECT UNIX_TIMESTAMP(now())*1000 AS test';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public async close(): Promise<boolean> {
|
|
41
|
+
return Promise.resolve(false);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public escape(query: any): string {
|
|
45
|
+
return this._connection.escape(query);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public async preQuery(): Promise<void> {
|
|
49
|
+
this._connection.config.namedPlaceholders = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public async query<R>(query, fields): Promise<RequestResults<R>> {
|
|
53
|
+
const [rows, outFields] = await this._connection.query(query, fields);
|
|
54
|
+
|
|
55
|
+
const castRows: RowDataPacket[] = rows as RowDataPacket[];
|
|
56
|
+
const castFields: FieldPacket[] = outFields;
|
|
57
|
+
|
|
58
|
+
const rval: RequestResults<R> = {
|
|
59
|
+
results: castRows as R,
|
|
60
|
+
fields: castFields,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
return rval;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public async modify(query: string, fields: Record<string, any>): Promise<RequestResults<ModifyResults>> {
|
|
67
|
+
const tmp: RequestResults<ModifyResults> = await this.query(query, fields);
|
|
68
|
+
return tmp;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public async onRequestSuccessOrFailure(_type: DatabaseRequestType): Promise<void> {
|
|
72
|
+
this._connection.config.namedPlaceholders = false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/*
|
|
76
|
+
public async onQueryFailureOnly(): Promise<void> {
|
|
77
|
+
return Promise.resolve(undefined);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public async onQuerySuccessOnly(): Promise<void> {
|
|
81
|
+
return Promise.resolve(undefined);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
*/
|
|
85
|
+
}
|