[fix] 多次调用 Open() 错误

This commit is contained in:
what 2023-06-21 09:56:28 +08:00
parent 9ec1f7b888
commit cd33e09d69

18
db.go
View File

@ -17,21 +17,19 @@ func (d *DB) SetLogger(f func(log Log)) *DB {
} }
func Open(config map[string]DBConfig) *DB { func Open(config map[string]DBConfig) *DB {
var configP = make(map[string]*DBConfig) if Engine == nil {
Engine = &DB{
for name := range config {
c := config[name]
configP[name] = &c
}
db := DB{
DatabaseManager: DatabaseManager{ DatabaseManager: DatabaseManager{
Configs: configP, Configs: make(map[string]*DBConfig),
Connections: make(map[string]*Connection), Connections: make(map[string]*Connection),
}, },
} }
}
Engine = &db for name := range config {
c := config[name]
Engine.Configs[name] = &c
}
return Engine return Engine
} }