-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Consider exporting parseDSN #224
Comments
Hi @xaprb, we are already considering that. |
My plan is to release v1.2 of the driver soon and then try moving the wire / protocol level stuff into a sub-package. No guarantees, that this is successful. At this point, I don't think the parseDSN function would be part of it. As you said yourself, it isn't obvious why it is helpful to be able to parse the DSN. There might be only very few corner cases where this is useful. Therefore I don't think parseDSN should be exported, but you can convince me otherwise 😉 |
I should have read our conversation history again, then. Still, I can see why exporting the dsn parsing would be useful. |
Giving this another thought, I don't think this is going to happen anytime soon. |
Or we make it an exported function with an obscene amount of return-values; returning each parameter and a map? I can see the need for it, it's probably pretty tedious and feels brittle to track our implementation. |
Then the function signature would be changing... |
I thought about this some more: What I propose below should be doable, stable and still helpful. At least it removes a heap of parsing if users of the driver replicate its functionality. type Dsn struct {
User string `json:"user"`
Pass string `json:"password,omitempty"`
Proto string `json:"protocol"`
Addr string `json:"address"`
Schema string `json:"schema,omitempty"`
Params map[string]string `json:"parameters,omitempty"`
}
func (d *Dsn) Parse(dsn string) error {
//...
} Making Users can call The only con I see is memory usage - and negligible in my opinion: values in the map are duplicated in config, one time in Params, one time in the parsed form (loc, ...). If desired (and supported by an interface func (c *config) Dsn() *Dsn {
tmp := *(c.Dsn)
tmp.Params = make(map[string]string, len(c.Params))
for k, v := range c.Params {
tmp.Params[k] = v
}
return &tmp
} |
I've just been writing some tests for an application that uses an environment variable to get its configuration, and one of the variables is a DSN. Part of my test is designed to try making a connection and handle the failures gracefully. The test itself also gets its config from the env var, which we set on CircleCI for example to connect to the database instance there. For these reasons it would be really helpful if my test could easily parse DSNs (maybe it's not obvious why, but that's the end result). For now I'm going to copy/paste parseDSN into my test file, but I do think this would be useful to export.
The text was updated successfully, but these errors were encountered: