Skip to content

Commit

Permalink
Adds onReserveConnection to Postgres and MySQL dialect configs (#996)
Browse files Browse the repository at this point in the history
Co-authored-by: Igal Klebanov <[email protected]>
  • Loading branch information
dcousineau and igalklebanov authored Jul 14, 2024
1 parent 5e60d76 commit f40f592
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/dialect/mysql/mysql-dialect-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ export interface MysqlDialectConfig {
* Called once for each created connection.
*/
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>

/**
* Called every time a connection is acquired from the connection pool.
*/
onReserveConnection?: (connection: DatabaseConnection) => Promise<void>
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/dialect/mysql/mysql-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export class MysqlDriver implements Driver {
}
}

if (this.#config?.onReserveConnection) {
await this.#config.onReserveConnection(connection)
}

return connection
}

Expand Down
5 changes: 5 additions & 0 deletions src/dialect/postgres/postgres-dialect-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ export interface PostgresDialectConfig {
* Called once for each created connection.
*/
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>

/**
* Called every time a connection is acquired from the pool.
*/
onReserveConnection?: (connection: DatabaseConnection) => Promise<void>
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/dialect/postgres/postgres-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export class PostgresDriver implements Driver {
}
}

if (this.#config.onReserveConnection) {
await this.#config.onReserveConnection(connection)
}

return connection
}

Expand Down

0 comments on commit f40f592

Please sign in to comment.