Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move aurora-pg driver to the aurora-pg driver directory (#6785
) for some reason the aurora postgres driver was living with the postgres driver - instead of in the directory explicitly for the aurora postgres driver. this moves the aurora-pg driver into that directory so there's a clearer delineation between the two drivers
- Loading branch information
1 parent
55fbb69
commit 89d83b3
Showing
4 changed files
with
131 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/driver/aurora-data-api-pg/AuroraDataApiPostgresDriver.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import {Driver} from "../Driver"; | ||
import {PostgresDriver} from "../postgres/PostgresDriver"; | ||
import {PlatformTools} from "../../platform/PlatformTools"; | ||
import {Connection} from "../../connection/Connection"; | ||
import {AuroraDataApiPostgresConnectionOptions} from "../aurora-data-api-pg/AuroraDataApiPostgresConnectionOptions"; | ||
import {AuroraDataApiPostgresQueryRunner} from "../aurora-data-api-pg/AuroraDataApiPostgresQueryRunner"; | ||
import {ReplicationMode} from "../types/ReplicationMode"; | ||
|
||
abstract class PostgresWrapper extends PostgresDriver { | ||
options: any; | ||
|
||
abstract createQueryRunner(mode: ReplicationMode): any; | ||
} | ||
|
||
export class AuroraDataApiPostgresDriver extends PostgresWrapper implements Driver { | ||
|
||
// ------------------------------------------------------------------------- | ||
// Public Properties | ||
// ------------------------------------------------------------------------- | ||
|
||
/** | ||
* Connection used by driver. | ||
*/ | ||
connection: Connection; | ||
|
||
/** | ||
* Aurora Data API underlying library. | ||
*/ | ||
DataApiDriver: any; | ||
|
||
client: any; | ||
|
||
// ------------------------------------------------------------------------- | ||
// Public Implemented Properties | ||
// ------------------------------------------------------------------------- | ||
|
||
/** | ||
* Connection options. | ||
*/ | ||
options: AuroraDataApiPostgresConnectionOptions; | ||
|
||
/** | ||
* Master database used to perform all write queries. | ||
*/ | ||
database?: string; | ||
|
||
// ------------------------------------------------------------------------- | ||
// Constructor | ||
// ------------------------------------------------------------------------- | ||
|
||
constructor(connection: Connection) { | ||
super(); | ||
this.connection = connection; | ||
this.options = connection.options as AuroraDataApiPostgresConnectionOptions; | ||
this.isReplicated = false; | ||
|
||
// load data-api package | ||
this.loadDependencies(); | ||
|
||
this.client = new this.DataApiDriver( | ||
this.options.region, | ||
this.options.secretArn, | ||
this.options.resourceArn, | ||
this.options.database, | ||
(query: string, parameters?: any[]) => this.connection.logger.logQuery(query, parameters), | ||
this.options.serviceConfigOptions, | ||
this.options.formatOptions, | ||
); | ||
} | ||
|
||
// ------------------------------------------------------------------------- | ||
// Public Implemented Methods | ||
// ------------------------------------------------------------------------- | ||
|
||
/** | ||
* Performs connection to the database. | ||
* Based on pooling options, it can either create connection immediately, | ||
* either create a pool and create connection when needed. | ||
*/ | ||
async connect(): Promise<void> { | ||
} | ||
|
||
/** | ||
* Closes connection with database. | ||
*/ | ||
async disconnect(): Promise<void> { | ||
} | ||
|
||
/** | ||
* Creates a query runner used to execute database queries. | ||
*/ | ||
createQueryRunner(mode: ReplicationMode) { | ||
return new AuroraDataApiPostgresQueryRunner(this, mode); | ||
} | ||
|
||
// ------------------------------------------------------------------------- | ||
// Protected Methods | ||
// ------------------------------------------------------------------------- | ||
|
||
/** | ||
* If driver dependency is not given explicitly, then try to load it via "require". | ||
*/ | ||
protected loadDependencies(): void { | ||
const { pg } = PlatformTools.load("typeorm-aurora-data-api-driver"); | ||
|
||
this.DataApiDriver = pg; | ||
} | ||
|
||
/** | ||
* Executes given query. | ||
*/ | ||
protected executeQuery(connection: any, query: string) { | ||
return this.client.query(query); | ||
} | ||
|
||
/** | ||
* Makes any action after connection (e.g. create extensions in Postgres driver). | ||
*/ | ||
async afterConnect(): Promise<void> { | ||
const extensionsMetadata = await this.checkMetadataForExtensions(); | ||
|
||
if (extensionsMetadata.hasExtensions) { | ||
await this.enableExtensions(extensionsMetadata, this.connection); | ||
} | ||
|
||
return Promise.resolve(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters