feat(user): 添加 GORM 代码生成工具并更新数据库配置

- 在项目中引入 GORM 相关依赖
- 添加 GORM代码生成工具 gen.go
- 更新 MySQL 数据库配置
- 新增 .env 文件到 .gitignore
This commit is contained in:
2025-01-17 17:54:00 +08:00
parent d696206dc7
commit e7ff1dc87d
10 changed files with 404 additions and 10 deletions
+4 -1
View File
@@ -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,