Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 404957f16a | |||
| 3d6871138a |
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
var (
|
||||
// MigrateTables 存储需要在数据库初始化时自动迁移的表
|
||||
MigrateTables []any = []any{}
|
||||
MigrateTables []any
|
||||
)
|
||||
|
||||
// NewDatabase 根据提供的驱动类型创建新的数据库连接
|
||||
@@ -25,6 +25,7 @@ var (
|
||||
// options: 数据库连接选项
|
||||
// 返回: GORM数据库实例
|
||||
func NewDatabase(driver string, dsn []string, options *types.SqlOptions) (db *gorm.DB, err error) {
|
||||
MigrateTables = make([]any, 0)
|
||||
driver = strings.ToLower(driver)
|
||||
switch driver {
|
||||
case "mysql":
|
||||
@@ -138,5 +139,8 @@ func NewPostgres(dsn []string, options *types.SqlOptions) (gormDb *gorm.DB, err
|
||||
//
|
||||
// - table: 需要自动迁移的表
|
||||
func AppendMigrate(table any) {
|
||||
if MigrateTables == nil {
|
||||
MigrateTables = make([]any, 0)
|
||||
}
|
||||
MigrateTables = append(MigrateTables, table)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user