-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Create a mysql.Connect
API.
#1045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
// You can use this function to create custom connector which dynamically | ||
// change the config. The cfg object must not be changed during calling | ||
// this function. | ||
func Connect(ctx context.Context, cfg *Config) (driver.Conn, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why use a pointer here if it's sensitive to concurrent changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because shallow copy of the config object is not a right way to copy config object.
Co-Authored-By: Márk Sági-Kazár <[email protected]>
This patch extends the API surface while it doesn't seem necessary (at least the description doesn't tell why it is necessary). As a counter example I implemented years ago a driver that wraps the MySQL driver to load creadentials from the |
If the need is to avoid formatting+parsing of DSNs, the |
Of course, I know it. I am the who proposed it first. Please read this issue and issue #1042 carefully. The need is not avoiding to parse DSN, but change the configuration (e.g. credential, server IP address, etc) on the fly. My main intension is to promote custom connector, instead of adding some dynamic (callback) options to the config object. Adding new API to help custom connector is not my main point. It is just a little helper function. I'm OK to reject this PR if people don't think this helper function is not worth enough. |
Description
This is a counter-proposal to #1042.
You can create a custom Connector object using this new API:
Checklist