1 | "use strict";
|
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3 | return new (P || (P = Promise))(function (resolve, reject) {
|
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
6 | function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
8 | });
|
9 | };
|
10 | Object.defineProperty(exports, "__esModule", { value: true });
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | class AuroraDataAPIClient {
|
16 | constructor(databaseRegion, awsSecretStoreArn, dbClusterOrInstanceArn, database, aws) {
|
17 | |
18 |
|
19 |
|
20 |
|
21 |
|
22 | this.listTables = () => __awaiter(this, void 0, void 0, function* () {
|
23 | this.Params.sqlStatements = 'SHOW TABLES';
|
24 | const response = yield this.RDS.executeSql(this.Params).promise();
|
25 | let tableList = [];
|
26 | const records = response['sqlStatementResults'][0]['resultFrame']['records'];
|
27 | for (const record of records) {
|
28 | tableList.push(record['values'][0]['stringValue']);
|
29 | }
|
30 | return tableList;
|
31 | });
|
32 | |
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | this.describeTable = (tableName) => __awaiter(this, void 0, void 0, function* () {
|
39 | this.Params.sqlStatements = `DESCRIBE ${tableName}`;
|
40 | const response = yield this.RDS.executeSql(this.Params).promise();
|
41 | const listOfColumns = response['sqlStatementResults'][0]['resultFrame']['records'];
|
42 | let columnDescriptions = [];
|
43 | for (const column of listOfColumns) {
|
44 | let colDescription = new ColumnDescription();
|
45 | const colValues = column['values'];
|
46 | colDescription.Field = colValues[MYSQL_DESCRIBE_TABLE_ORDER.Field]['stringValue'];
|
47 | colDescription.Type = colValues[MYSQL_DESCRIBE_TABLE_ORDER.Type]['stringValue'];
|
48 | colDescription.Null = colValues[MYSQL_DESCRIBE_TABLE_ORDER.Null]['stringValue'];
|
49 | colDescription.Key = colValues[MYSQL_DESCRIBE_TABLE_ORDER.Key]['stringValue'];
|
50 | colDescription.Default = colValues[MYSQL_DESCRIBE_TABLE_ORDER.Default]['stringValue'];
|
51 | colDescription.Extra = colValues[MYSQL_DESCRIBE_TABLE_ORDER.Extra]['stringValue'];
|
52 | columnDescriptions.push(colDescription);
|
53 | }
|
54 | return columnDescriptions;
|
55 | });
|
56 | |
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | this.getTableForeignKeyReferences = (tableName) => __awaiter(this, void 0, void 0, function* () {
|
63 | this.Params.sqlStatements = `SELECT TABLE_NAME FROM information_schema.key_column_usage
|
64 | WHERE referenced_table_name is not null
|
65 | AND REFERENCED_TABLE_NAME = '${tableName}';`;
|
66 | const response = yield this.RDS.executeSql(this.Params).promise();
|
67 | let tableList = [];
|
68 | const records = response['sqlStatementResults'][0]['resultFrame']['records'];
|
69 | for (const record of records) {
|
70 | tableList.push(record['values'][0]['stringValue']);
|
71 | }
|
72 | return tableList;
|
73 | });
|
74 | this.AWS = aws;
|
75 | this.AWS.config.update({
|
76 | region: databaseRegion
|
77 | });
|
78 | this.RDS = new this.AWS.RDSDataService();
|
79 | this.Params = new DataApiParams();
|
80 | this.Params.awsSecretStoreArn = awsSecretStoreArn;
|
81 | this.Params.dbClusterOrInstanceArn = dbClusterOrInstanceArn;
|
82 | this.Params.database = database;
|
83 | }
|
84 | setRDSClient(rdsClient) {
|
85 | this.RDS = rdsClient;
|
86 | }
|
87 | }
|
88 | exports.AuroraDataAPIClient = AuroraDataAPIClient;
|
89 | class DataApiParams {
|
90 | }
|
91 | exports.DataApiParams = DataApiParams;
|
92 | class ColumnDescription {
|
93 | }
|
94 | exports.ColumnDescription = ColumnDescription;
|
95 | var MYSQL_DESCRIBE_TABLE_ORDER;
|
96 | (function (MYSQL_DESCRIBE_TABLE_ORDER) {
|
97 | MYSQL_DESCRIBE_TABLE_ORDER[MYSQL_DESCRIBE_TABLE_ORDER["Field"] = 0] = "Field";
|
98 | MYSQL_DESCRIBE_TABLE_ORDER[MYSQL_DESCRIBE_TABLE_ORDER["Type"] = 1] = "Type";
|
99 | MYSQL_DESCRIBE_TABLE_ORDER[MYSQL_DESCRIBE_TABLE_ORDER["Null"] = 2] = "Null";
|
100 | MYSQL_DESCRIBE_TABLE_ORDER[MYSQL_DESCRIBE_TABLE_ORDER["Key"] = 3] = "Key";
|
101 | MYSQL_DESCRIBE_TABLE_ORDER[MYSQL_DESCRIBE_TABLE_ORDER["Default"] = 4] = "Default";
|
102 | MYSQL_DESCRIBE_TABLE_ORDER[MYSQL_DESCRIBE_TABLE_ORDER["Extra"] = 5] = "Extra";
|
103 | })(MYSQL_DESCRIBE_TABLE_ORDER || (MYSQL_DESCRIBE_TABLE_ORDER = {}));
|
104 |
|
\ | No newline at end of file |