jmoiron / sqlx

general purpose extensions to golang's database/sql
http://jmoiron.github.io/sqlx/
MIT License
16.3k stars 1.09k forks source link

Creating a connection pool with custom connector #929

Open SebastienMelki opened 5 months ago

SebastienMelki commented 5 months ago

Hello,

We are using IAM Authentication in order to connect to an RDS mysql cluster. We are encountering a problem: the credentials that the connection pool is using have to be modified every 15 minutes, because AWS only provide tokens with a TTL of 15 minutes.

A solution to use IAM with connection pooling and the mysql driver is described here https://github.com/go-sql-driver/mysql/issues/1354 but it involves using a custom connector. It seems to be using sql.OpenDB() instead of sql.Open().

Is there a way to use a custom connector with sqlx? I couldn't find a way to plug it in.

If not, is there a recommended way to use sqlx mysql connection pools with aws IAM?

Thank you

mpalmer commented 3 weeks ago

By the looks of it, you can (probably) get what you need by creating your driver.Connector, passing that to sql.OpenDB(), and then passing the resulting sql.DB to sqlx.NewDB().