Skip to content

Commit

Permalink
Recognize URL as conn string and automagically do the right thing
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciek Sakrejda committed Oct 4, 2013
1 parent 5b16002 commit 8875df5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func Open(name string) (_ driver.Conn, err error) {
o.Set(k, v)
}

if strings.HasPrefix(name, "postgres://") {
name, err = ParseURL(name)
if err != nil {
return nil, err
}
}

if err := parseOpts(name, o); err != nil {
return nil, err
}
Expand Down
18 changes: 18 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ func openTestConn(t Fatalistic) *sql.DB {
return conn
}

func TestOpenURL(t *testing.T) {
datname := os.Getenv("PGDATABASE")
sslmode := os.Getenv("PGSSLMODE")
if datname == "" {
os.Setenv("PGDATABASE", "pqgotest")
}

if sslmode == "" {
os.Setenv("PGSSLMODE", "disable")
}

conn, err := sql.Open("postgres", "postgres://")
if err != nil {
t.Fatal(err)
}
conn.Close()
}

func TestExec(t *testing.T) {
db := openTestConn(t)
defer db.Close()
Expand Down

0 comments on commit 8875df5

Please sign in to comment.