diff --git a/system.go b/system.go index c1151d6..6ccad6b 100644 --- a/system.go +++ b/system.go @@ -9,6 +9,7 @@ package mysql import ( "fmt" + "gorm.io/driver/mysql" "gorm.io/gorm" ) @@ -21,6 +22,17 @@ import ( type SystemDao struct { } +// Connect 连接数据库 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 17:58 2023/4/9 +func (sd *SystemDao) Connect(host string, port string, user string, password string, database string) (*gorm.DB, error) { + // db, err := gorm.Open("mysql", "root:root@(localhost)/gorm-test?charset=utf8mb4&parseTime=True&loc=Local") + conn := fmt.Sprintf("%v:%v@(%v:%v)/%v?charset=utf8mb4&parseTime=True&loc=Local", user, password, host, port, database) + return gorm.Open(mysql.Open(conn), &gorm.Config{}) +} + // SelectDatabase 切换数据库 // // Author : go_developer@163.com<白茶清欢>