go-gorm / postgres

GORM PostgreSQL driver
MIT License
228 stars 120 forks source link

Add posibility to define connection hooks #186

Closed lchelmickiolx closed 1 year ago

lchelmickiolx commented 1 year ago

What did this pull request do?

It gives the possibility to define BeforeConnect and AfterConnect on stdlib connection.

User Case Description

Generate an IAM Auth password for RDS just before a new connection is opened. Tokens are valid for only 15 minutes, so after w while they have to be regenerated, for the pool to be able to open new connections

jinzhu commented 1 year ago

Hi @lchelmickiolx

How about passing the connection pool like this:

conn := stdlib.OpenDB(*config, OptionOpenDB...)

postgres.New(postgres.Config{
  Conn: conn,
})

The change seems to bind the current driver into the GORM driver too much, we doesn't want to do that, thank you for your unerstanding.