upper / db

Data Access Layer (DAL) for PostgreSQL, CockroachDB, MySQL, SQLite and MongoDB with ORM-like features.
https://upper.io/
MIT License
3.54k stars 235 forks source link

If mysql db has multiple instance objects, is there a problem here? #630

Closed daheige closed 3 years ago

daheige commented 3 years ago

https://github.com/upper/db/blob/6d34eff2084ed3b148d5d7df13630a122180d347/adapter.go#L55

// RegisterAdapter registers a generic database adapter.
func RegisterAdapter(name string, adapter Adapter) {
    adapterMapMu.Lock()
    defer adapterMapMu.Unlock()

    if name == "" {
        panic(`Missing adapter name`)
    }
    if _, ok := adapterMap[name]; ok {
        panic(`db.RegisterAdapter() called twice for adapter: ` + name)
    }
    adapterMap[name] = adapter
}

adapterMap var,this way of adapterMap is problematic In business scenarios, different mysql db instances will be used. If there is a mysql name here, panic will occur if you look at the code here. I think this is unreasonable. Can you improve it?