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

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

20
db.go
View File

@ -17,22 +17,20 @@ 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{
DatabaseManager: DatabaseManager{
Configs: make(map[string]*DBConfig),
Connections: make(map[string]*Connection),
},
}
}
for name := range config { for name := range config {
c := config[name] c := config[name]
configP[name] = &c Engine.Configs[name] = &c
} }
db := DB{
DatabaseManager: DatabaseManager{
Configs: configP,
Connections: make(map[string]*Connection),
},
}
Engine = &db
return Engine return Engine
} }