wangpengfei
2023-08-25 25c573d55986e02cf5f70cc3868e2b94a4be98e2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package initialize
 
import (
    "gorm.io/gorm"
    "srm/config"
    "srm/global"
)
 
const sys = "system"
 
func DBList() {
    dbMap := make(map[string]*gorm.DB)
    for _, info := range global.GVA_CONFIG.DBList {
        if info.Disable {
            continue
        }
        switch info.Type {
        case "mysql":
            dbMap[info.AliasName] = GormMysqlByConfig(config.Mysql{GeneralDB: info.GeneralDB})
        case "mssql":
            dbMap[info.AliasName] = GormMssqlByConfig(config.Mssql{GeneralDB: info.GeneralDB})
        case "pgsql":
            dbMap[info.AliasName] = GormPgSqlByConfig(config.Pgsql{GeneralDB: info.GeneralDB})
        case "oracle":
            dbMap[info.AliasName] = GormOracleByConfig(config.Oracle{GeneralDB: info.GeneralDB})
        default:
            continue
        }
    }
    // 做特殊判断,是否有迁移
    // 适配低版本迁移多数据库版本
    if sysDB, ok := dbMap[sys]; ok {
        global.GVA_DB = sysDB
    }
    global.GVA_DBList = dbMap
}