From 860fe73996ee9a39e210e02bdcec90b5ba0405fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 9 Apr 2023 18:03:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AE=80=E5=8D=95=E7=9A=84?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E8=BF=9E=E6=8E=A5=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- system.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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<白茶清欢>