-
Notifications
You must be signed in to change notification settings - Fork 18k
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
database/sql: Open() doesn't actually open a connection #4804
Labels
Comments
Good point. I've ended up implementing that myself a number of times. Alternatively/additionally, I'd like to see a *DB and optional Driver way to do: // Ping returns whether the database is available. func (*DB) Ping() error But ignoring Ping for now, I think Open getting (& maybe returning or returning in n seconds) a connection is a good default policy. But I'd like drivers to be able to opt-out of it. I'd make a new optional interface on Driver like: // OpenInitialer is an optional interface that may be implemented by drivers which // have a preference on whether an initial connection is created on sql.Open to // determine the health of the database. OpenInitial should behave exactly like // Driver.Open, but the ErrSkip value may be returned to indicate that an initial // connection should not be opened. type OpenInitialer interface { OpenInitial(name string) (Conn, error) } Want to do this? Labels changed: removed priority-triage. Status changed to Accepted. |
Mhm, Ping() sounds useful. Time to undeprecate https://github.com/Go-SQL-Driver/MySQL/blob/master/connection.go#L319 The optional opt-out seems fine to me. Right now I have no time to implement this since it's finals time (fun fact: next one is on ... surprise: databases) so don't hesitate to start working on this. |
The finals are mastered, so I start working on this now. Whats your opinion on yet another optional interface which allows to "clone" connections? So the driver doesn't need to parse the DSN again. Maybe the driver also queried some server vars which could be taken over instead of querying them again or there are some other checks / operations a driver might skip. So the first connection is opened with Driver.OpenInitial(dsn) and for all further connections opened internally by the sql package just Conn.Clone(). |
Sent out https://golang.org/cl/7819043 Owner changed to @bradfitz. Status changed to Started. |
This issue was closed by revision a4a8651. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: