qustavo / sqlhooks

Attach hooks to any database/sql driver
MIT License
652 stars 44 forks source link

feat: support driver.DriverContext interface #44

Open conradludgate opened 3 years ago

conradludgate commented 3 years ago

sql.Open internally makes use of the DriverContext interface, and if a Driver does not implement it, it creates a light wrapper1.

This DriverContext provides better context support as well as providing some useful error checking upfront. For instance, the mysql driver can check the DSN value before opening a connection to see if it's well formed. That way you get an error instantly instead of an error when making your first sql query

1: https://github.com/golang/go/blob/d0dd26a88c019d54f22463daae81e785f5867565/src/database/sql/sql.go#L832 https://github.com/golang/go/blob/d0dd26a88c019d54f22463daae81e785f5867565/src/database/sql/sql.go#L755-L766

qustavo commented 3 years ago

Hey @conradludgate thanks for doing this, it looks like a great contribution! Is there any way to test this?

conradludgate commented 3 years ago

Hey @conradludgate thanks for doing this, it looks like a great contribution! Is there any way to test this?

Sure! I'll look into it later