From 28e052299341468380db57677ec8da2309efc9f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Flc=E3=82=9B?= Date: Tue, 28 Mar 2023 15:06:01 +0800 Subject: [PATCH] fix: rename `Db` to `DB` --- dsn.go | 6 +++--- dsn_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) 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) {