Parse postgresql:// protocol
This commit is contained in:
@@ -152,7 +152,7 @@ func ParseConfig(connString string) (*Config, error) {
|
|||||||
|
|
||||||
if connString != "" {
|
if connString != "" {
|
||||||
// connString may be a database URL or a DSN
|
// connString may be a database URL or a DSN
|
||||||
if strings.HasPrefix(connString, "postgres://") {
|
if strings.HasPrefix(connString, "postgres://") || strings.HasPrefix(connString, "postgresql://") {
|
||||||
err := addURLSettings(settings, connString)
|
err := addURLSettings(settings, connString)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, &parseConfigError{connString: connString, msg: "failed to parse as URL", err: err}
|
return nil, &parseConfigError{connString: connString, msg: "failed to parse as URL", err: err}
|
||||||
|
|||||||
@@ -214,6 +214,18 @@ func TestParseConfig(t *testing.T) {
|
|||||||
RuntimeParams: map[string]string{},
|
RuntimeParams: map[string]string{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "database url postgresql protocol",
|
||||||
|
connString: "postgresql://jack@localhost:5432/mydb?sslmode=disable",
|
||||||
|
config: &pgconn.Config{
|
||||||
|
User: "jack",
|
||||||
|
Host: "localhost",
|
||||||
|
Port: 5432,
|
||||||
|
Database: "mydb",
|
||||||
|
TLSConfig: nil,
|
||||||
|
RuntimeParams: map[string]string{},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "DSN everything",
|
name: "DSN everything",
|
||||||
connString: "user=jack password=secret host=localhost port=5432 database=mydb sslmode=disable application_name=pgxtest search_path=myschema",
|
connString: "user=jack password=secret host=localhost port=5432 database=mydb sslmode=disable application_name=pgxtest search_path=myschema",
|
||||||
|
|||||||
Reference in New Issue
Block a user