From 4095a3fb252cdfcbbc471d0d547d63eebc0e9f7c Mon Sep 17 00:00:00 2001 From: anakin Date: Fri, 21 Jun 2019 16:05:34 +0800 Subject: [PATCH 1/2] add mysql support add mysql support --- database/database.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/database/database.go b/database/database.go index 114ce5aa..4a89e59f 100644 --- a/database/database.go +++ b/database/database.go @@ -49,6 +49,21 @@ func NewDatabase(cnf *config.Config) (*gorm.DB, error) { return db, nil } + if cnf.Database.Type == "mysql" { + args := fmt.Sprintf( + "%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True", + cnf.Database.User, + cnf.Database.Password, + cnf.Database.Host, + cnf.Database.Port, + cnf.Database.DatabaseName, + ) + db, err := gorm.Open("mysql", args) + if err != nil { + return db, err + } + return db, nil + } // Database type not supported return nil, fmt.Errorf("Database type %s not suppported", cnf.Database.Type) From bbc39ac178d3114809e09535063e0462cf928f5c Mon Sep 17 00:00:00 2001 From: anakin Date: Fri, 21 Jun 2019 16:06:43 +0800 Subject: [PATCH 2/2] fixed SQL error when use mysql fixed SQL error when use mysql --- oauth/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oauth/client.go b/oauth/client.go index bd7f7f24..0b5ed84c 100644 --- a/oauth/client.go +++ b/oauth/client.go @@ -31,7 +31,7 @@ func (s *Service) ClientExists(clientID string) bool { func (s *Service) FindClientByClientID(clientID string) (*models.OauthClient, error) { // Client IDs are case insensitive client := new(models.OauthClient) - notFound := s.db.Where("key = LOWER(?)", clientID). + notFound := s.db.Where("`key` = LOWER(?)", clientID). First(client).RecordNotFound() // Not found