增加简单的数据库连接方法
This commit is contained in:
parent
f9e94c3769
commit
860fe73996
12
system.go
12
system.go
@ -9,6 +9,7 @@ package mysql
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"gorm.io/driver/mysql"
|
||||||
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
@ -21,6 +22,17 @@ import (
|
|||||||
type SystemDao struct {
|
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 切换数据库
|
// SelectDatabase 切换数据库
|
||||||
//
|
//
|
||||||
// Author : go_developer@163.com<白茶清欢>
|
// Author : go_developer@163.com<白茶清欢>
|
||||||
|
Loading…
Reference in New Issue
Block a user