diff --git a/dsn.go b/dsn.go index 19bd8d15..642ff8c1 100644 --- a/dsn.go +++ b/dsn.go @@ -10,14 +10,14 @@ type DSN struct { Port int User string Pass string - Db string + DB string Options map[string]string } func (d DSN) String() string { - dsn := d.User + ":" + d.Pass + "@tcp(" + d.Host + ":" + strconv.Itoa(d.Port) + ")/" + d.Db + dsn := d.User + ":" + d.Pass + "@tcp(" + d.Host + ":" + strconv.Itoa(d.Port) + ")/" + d.DB - if d.Options != nil { + if d.Options != nil && len(d.Options) > 0 { value := url.Values{} for k, v := range d.Options { diff --git a/dsn_test.go b/dsn_test.go index 77f2c845..257515f2 100644 --- a/dsn_test.go +++ b/dsn_test.go @@ -8,7 +8,7 @@ func TestDsn(t *testing.T) { Port: 3306, User: "root", Pass: "password", - Db: "gorm", + DB: "gorm", } t.Run("dsn string", func(t *testing.T) {