diff --git a/initialize/gorm.go b/initialize/gorm.go new file mode 100644 index 0000000..5679d03 --- /dev/null +++ b/initialize/gorm.go @@ -0,0 +1,24 @@ +package initialize + +import ( + "gorm.io/gorm" + "sundynix-go/global" +) + +// Gorm 根据全局配置中的数据库类型返回对应的 *gorm.DB 实例。 +// 该函数通过检查 global.Config.System.DbType 的值来决定使用哪种数据库连接。 +// +// 返回值: +// - *gorm.DB: 返回对应数据库类型的 *gorm.DB 实例 +func Gorm() *gorm.DB { + switch global.Config.System.DbType { + case "mysql": + return GormMysql() // 返回 MySQL 数据库的 *gorm.DB 实例 + case "pgsql": + return GromPgsql() // 返回 PostgreSQL 数据库的 *gorm.DB 实例 + case "sqlite": + return GormSqlite() // 返回 SQLite 数据库的 *gorm.DB 实例 + default: + return GormMysql() // 默认返回 MySQL 数据库的 *gorm.DB 实例 + } +}