2
0

Allow dbname query parameter in URL conn string

fixes #69
This commit is contained in:
Jack Christensen
2021-04-09 18:20:06 -05:00
parent 464a7d88d9
commit 3f76b98073
2 changed files with 20 additions and 0 deletions
+8
View File
@@ -426,7 +426,15 @@ func parseURLSettings(connString string) (map[string]string, error) {
settings["database"] = database
}
nameMap := map[string]string{
"dbname": "database",
}
for k, v := range url.Query() {
if k2, present := nameMap[k]; present {
k = k2
}
settings[k] = v[0]
}
+12
View File
@@ -227,6 +227,18 @@ func TestParseConfig(t *testing.T) {
RuntimeParams: map[string]string{},
},
},
{
name: "database url dbname",
connString: "postgres://localhost/?dbname=foo&sslmode=disable",
config: &pgconn.Config{
User: osUserName,
Host: "localhost",
Port: 5432,
Database: "foo",
TLSConfig: nil,
RuntimeParams: map[string]string{},
},
},
{
name: "database url postgresql protocol",
connString: "postgresql://jack@localhost:5432/mydb?sslmode=disable",