Skip to content

Commit f5d6d2c

Browse files
feat: upgrade to AWS SDK v3
1 parent 0770c1b commit f5d6d2c

File tree

4 files changed

+2303
-303
lines changed

4 files changed

+2303
-303
lines changed

index.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// AWS Aurora MySQL Data API Client
22
// -------
3+
const { ExecuteStatementCommand, RDSDataClient } = require('@aws-sdk/client-rds-data');
4+
const { NodeHttpHandler } = require('@smithy/node-http-handler');
35
const map = require('lodash.map');
46
const Client_MySQL = require('knex/lib/dialects/mysql'); // eslint-disable-line camelcase
57
const Transaction = require('./transaction');
@@ -61,23 +63,27 @@ class Client_AuroraDataMySQL extends Client_MySQL { // eslint-disable-line camel
6163
_driver () {
6264
let RDSDataService;
6365
try {
64-
RDSDataService = require('aws-sdk/clients/rdsdataservice');
66+
RDSDataService = RDSDataClient;
6567
} catch (err) { /* istanbul ignore next */
6668
throw new Error(`Failed to load aws-sdk rdsdataservice client, did you forget to install it as a dependency? (${err.message})`);
6769
}
6870

69-
const https = this.config.connection.sdkConfig && String(this.config.connection.sdkConfig.endpoint).startsWith('http:')
71+
const isHttp = this.config.connection.sdkConfig && String(this.config.connection.sdkConfig.endpoint).startsWith('http:');
72+
73+
const https = isHttp
7074
? require('http')
7175
: require('https');
7276

7377
const agent = new https.Agent({
7478
keepAlive: true
7579
});
7680

81+
const requestHandler = new NodeHttpHandler({
82+
[isHttp ? 'httpAgent' : 'httpsAgent']: agent
83+
});
84+
7785
const config = {
78-
httpOptions: {
79-
agent
80-
},
86+
requestHandler,
8187
...(this.config.connection.sdkConfig || {})
8288
};
8389

@@ -221,9 +227,9 @@ class Client_AuroraDataMySQL extends Client_MySQL { // eslint-disable-line camel
221227
params.transactionId = connection.transactions[connection.__knexTxId];
222228
}
223229

224-
obj.data = await connection.client
225-
.executeStatement(params)
226-
.promise();
230+
const command = new ExecuteStatementCommand(params);
231+
232+
obj.data = await connection.client.send(command);
227233

228234
return obj;
229235
}

0 commit comments

Comments
 (0)