Skip to content

Commit

Permalink
Adds onReserveConnection to Postgres and MySQL dialect configs (kys…
Browse files Browse the repository at this point in the history
…ely-org#996)

Co-authored-by: Igal Klebanov <[email protected]>
  • Loading branch information
2 people authored and thecodrr committed Sep 3, 2024
1 parent 302f6fb commit cb762b5
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 cb762b5

Please sign in to comment.