Skip to content

Commit

Permalink
Merge pull request #23 from txase/feature/aws-sdk-v3
Browse files Browse the repository at this point in the history
Feat: Upgrade to AWS SDK v3
  • Loading branch information
txase authored Dec 20, 2023
2 parents 0770c1b + c71ba83 commit a2ab921
Show file tree
Hide file tree
Showing 6 changed files with 6,947 additions and 4,172 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ knex.transaction(async trx => {
```
## Breaking Changes
### Version 2 to 3
Version 3 uses version 3 of the AWS SDK. This SDK is included automatically in the `nodejs18.x` AWS Lambda runtime and above.
`@aws-sdk/client-rds-data` and `@smithy/node-http-handler` are only included as dev dependencies. You will need to make sure those two packages are available in some form in your project.
### Version 1 to 2
Version 1 depended on aws-sdk, which at the time of the change was 71 MB in size. This package may be used in contexts where package size is important and the SDK may already be available, such as AWS Lambda Functions.
Expand Down
22 changes: 14 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// AWS Aurora MySQL Data API Client
// -------
const { ExecuteStatementCommand, RDSDataClient } = require('@aws-sdk/client-rds-data');
const { NodeHttpHandler } = require('@smithy/node-http-handler');
const map = require('lodash.map');
const Client_MySQL = require('knex/lib/dialects/mysql'); // eslint-disable-line camelcase
const Transaction = require('./transaction');
Expand Down Expand Up @@ -61,23 +63,27 @@ class Client_AuroraDataMySQL extends Client_MySQL { // eslint-disable-line camel
_driver () {
let RDSDataService;
try {
RDSDataService = require('aws-sdk/clients/rdsdataservice');
RDSDataService = RDSDataClient;
} catch (err) { /* istanbul ignore next */
throw new Error(`Failed to load aws-sdk rdsdataservice client, did you forget to install it as a dependency? (${err.message})`);
}

const https = this.config.connection.sdkConfig && String(this.config.connection.sdkConfig.endpoint).startsWith('http:')
const isHttp = this.config.connection.sdkConfig && String(this.config.connection.sdkConfig.endpoint).startsWith('http:');

const https = isHttp
? require('http')
: require('https');

const agent = new https.Agent({
keepAlive: true
});

const requestHandler = new NodeHttpHandler({
[isHttp ? 'httpAgent' : 'httpsAgent']: agent
});

const config = {
httpOptions: {
agent
},
requestHandler,
...(this.config.connection.sdkConfig || {})
};

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

obj.data = await connection.client
.executeStatement(params)
.promise();
const command = new ExecuteStatementCommand(params);

obj.data = await connection.client.send(command);

return obj;
}
Expand Down
Loading

0 comments on commit a2ab921

Please sign in to comment.