Skip to content

Commit

Permalink
feat: aurora Data API - Support for AWS configuration options through…
Browse files Browse the repository at this point in the history
… aurora driver (#5754)

* AWS.ConfigurationOptions added to AuroraDataApiConnectionOptions

Updated typeorm-aurora-data-api-driver to 1.2.0 for the support of the new constructor argument.

* Unit test for aurora-data-api driver and validation that service config options are passed

* Leaving skip to false for aurora seems to fail some unit tests
  • Loading branch information
cklam2 authored May 16, 2020
1 parent 8ac5d5d commit 1829f96
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 8 deletions.
13 changes: 13 additions & 0 deletions ormconfig.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,18 @@
"logging": false,
"useNewUrlParser": true,
"useUnifiedTopology": true
},
{
"skip": true,
"name": "aurora-data-api",
"type": "aurora-data-api",
"region": "us-east-1",
"secretArn": "mysecret",
"resourceArn": "app-dbcluster",
"database": "app-dbcluster-mine",
"serviceConfigOptions": {
"maxRetries": 3
},
"logging": false
}
]
13 changes: 6 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"sqlite3": "^4.0.9",
"ts-node": "^8.0.2",
"tslint": "^5.13.1",
"typeorm-aurora-data-api-driver": "^1.1.1",
"typeorm-aurora-data-api-driver": "^1.2.0",
"typescript": "^3.3.3333"
},
"dependencies": {
Expand Down
2 changes: 2 additions & 0 deletions src/driver/aurora-data-api/AuroraDataApiConnectionOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface AuroraDataApiConnectionOptions extends BaseConnectionOptions, A

readonly database: string;

readonly serviceConfigOptions?: { [key: string]: any }; // pass optional AWS.ConfigurationOptions here

/**
* Use spatial functions like GeomFromText and AsText which are removed in MySQL 8.
* (Default: true)
Expand Down
1 change: 1 addition & 0 deletions src/driver/aurora-data-api/AuroraDataApiDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export class AuroraDataApiDriver implements Driver {
this.options.resourceArn,
this.options.database,
(query: string, parameters?: any[]) => this.connection.logger.logQuery(query, parameters),
this.options.serviceConfigOptions
);

// validate options to make sure everything is set
Expand Down
21 changes: 21 additions & 0 deletions test/functional/connection-manager/connection-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import {PrimaryGeneratedColumn} from "../../../src/decorator/columns/PrimaryGene
import {Column} from "../../../src/decorator/columns/Column";
import {Entity} from "../../../src/decorator/entity/Entity";

// Uncomment when testing the aurora data API driver
// import {AuroraDataApiDriver} from "../../../src/driver/aurora-data-api/AuroraDataApiDriver";
// import {AuroraDataApiConnectionOptions} from "../../../src/driver/aurora-data-api/AuroraDataApiConnectionOptions";

describe("ConnectionManager", () => {

@Entity()
Expand Down Expand Up @@ -68,6 +72,23 @@ describe("ConnectionManager", () => {
connection.driver.should.be.instanceOf(MysqlDriver);
connection.isConnected.should.be.true;
await connection.close();
it("should create a aurora connection when aurora-data-api driver is specified", async () => {
const options = setupSingleTestingConnection("aurora-data-api", {
name: "aurora-data-api",
dropSchema: false,
schemaCreate: false,
enabledDrivers: ["aurora-data-api"]
});
const connectionManager = new ConnectionManager();
const connection = connectionManager.create(options!);
await connection.connect();
connection.name.should.contain("aurora-data-api");
connection.driver.should.be.instanceOf(AuroraDataApiDriver);
connection.isConnected.should.be.true;
const serviceConfigOptions = (connection.options as AuroraDataApiConnectionOptions).serviceConfigOptions;
expect(serviceConfigOptions).to.include({ maxRetries: 3, region: "us-east-1" });
await connection.close();
});
/!* it("should create a postgres connection when postgres driver is specified AND connect to it", async () => {
Expand Down

0 comments on commit 1829f96

Please sign in to comment.