feat(user): 添加 GORM 代码生成工具并更新数据库配置
- 在项目中引入 GORM 相关依赖 - 添加 GORM代码生成工具 gen.go - 更新 MySQL 数据库配置 - 新增 .env 文件到 .gitignore
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package mysql
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/suyiiyii/hertz101/app/user/conf"
|
||||
"os"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
"gorm.io/gorm"
|
||||
@@ -13,7 +15,8 @@ var (
|
||||
)
|
||||
|
||||
func Init() {
|
||||
DB, err = gorm.Open(mysql.Open(conf.GetConf().MySQL.DSN),
|
||||
dsn := fmt.Sprintf(conf.GetConf().MySQL.DSN, os.Getenv("MYSQL_USER"), os.Getenv("MYSQL_PASSWORD"), os.Getenv("MYSQL_HOST"))
|
||||
DB, err = gorm.Open(mysql.Open(dsn),
|
||||
&gorm.Config{
|
||||
PrepareStmt: true,
|
||||
SkipDefaultTransaction: true,
|
||||
|
||||
Reference in New Issue
Block a user