Skip to content

Commit

Permalink
feat: add AWS configurationOptions to aurora-data-api-pg connector (#…
Browse files Browse the repository at this point in the history
…6106)

Co-authored-by: Sergio Durban Belmonte <sdurban@leadtech.com>
  • Loading branch information
sdurban and sdurban committed May 24, 2020
1 parent 650b716 commit 203f51d
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
13 changes: 13 additions & 0 deletions ormconfig.json.dist
Expand Up @@ -103,5 +103,18 @@
"maxRetries": 3
},
"logging": false
},
{
"skip": true,
"name": "aurora-data-api-pg",
"type": "aurora-data-api-pg",
"region": "us-east-1",
"secretArn": "mysecret",
"resourceArn": "app-dbcluster",
"database": "app-dbcluster-mine",
"serviceConfigOptions": {
"maxRetries": 3
},
"logging": false
}
]
51 changes: 17 additions & 34 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
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.2.0",
"typeorm-aurora-data-api-driver": "^1.3.0",
"typescript": "^3.3.3333"
},
"dependencies": {
Expand Down
Expand Up @@ -31,4 +31,6 @@ export interface AuroraDataApiPostgresConnectionOptions extends BaseConnectionOp
* Defaults to logging error with `warn` level.
*/
readonly poolErrorHandler?: (err: any) => any;

readonly serviceConfigOptions?: { [key: string]: any };
}
1 change: 1 addition & 0 deletions src/driver/postgres/PostgresDriver.ts
Expand Up @@ -1039,6 +1039,7 @@ export class AuroraDataApiPostgresDriver extends PostgresWrapper {
this.options.resourceArn,
this.options.database,
(query: string, parameters?: any[]) => this.connection.logger.logQuery(query, parameters),
this.options.serviceConfigOptions
);
}

Expand Down
20 changes: 20 additions & 0 deletions test/functional/connection-manager/connection-manager.ts
Expand Up @@ -10,6 +10,8 @@ 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";
// import {AuroraDataApiPostgresDriver} from "../../../src/driver/postgres/PostgresDriver";
// import {AuroraDataApiPostgresConnectionOptions} from "../../../src/driver/aurora-data-api-pg/AuroraDataApiPostgresConnectionOptions";

describe("ConnectionManager", () => {

Expand Down Expand Up @@ -91,6 +93,24 @@ describe("ConnectionManager", () => {
await connection.close();
});
it("should create a aurora connection when aurora-data-api-pg driver is specified", async () => {
const options = setupSingleTestingConnection("aurora-data-api-pg", {
name: "aurora-data-api-pg",
dropSchema: false,
schemaCreate: false,
enabledDrivers: ["aurora-data-api-pg"]
});
const connectionManager = new ConnectionManager();
const connection = connectionManager.create(options!);
await connection.connect();
connection.name.should.contain("aurora-data-api-pg");
connection.driver.should.be.instanceOf(AuroraDataApiPostgresDriver);
connection.isConnected.should.be.true;
const serviceConfigOptions = (connection.options as AuroraDataApiPostgresConnectionOptions).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 () => {
const options: ConnectionOptions = {
name: "myPostgresConnection",
Expand Down

0 comments on commit 203f51d

Please sign in to comment.