28 lines
625 B
Go
28 lines
625 B
Go
package with
|
|
|
|
import (
|
|
"git.apinb.com/bsm-sdk/core/conf"
|
|
"git.apinb.com/bsm-sdk/core/database"
|
|
"git.apinb.com/bsm-sdk/core/printer"
|
|
"git.apinb.com/bsm-sdk/core/types"
|
|
"git.apinb.com/bsm-sdk/core/vars"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func Databases(cfg *conf.DBConf, opts *types.SqlOptions) *gorm.DB {
|
|
if cfg == nil || len(cfg.Source) == 0 {
|
|
panic("No Database Source Found !")
|
|
}
|
|
|
|
// print inform.
|
|
printer.Info("[BSM - %s] Databases: %v", vars.ServiceKey, cfg)
|
|
|
|
var err error
|
|
db, err := database.NewDatabase(cfg.Driver, cfg.Source, opts)
|
|
if err != nil {
|
|
printer.Error("Database Init Failed !")
|
|
panic(err)
|
|
}
|
|
return db
|
|
}
|