// GetDb - Will return instance of database connection func (bs *BridgeService) GetDb() (db gorm.DB, err error) { var service mysql.Adapter if service, err = bs.Connections.Get(DbAccessName); err != nil { return } db = service.Adapter().(*mysql.Connection).DB return }
// AttachSQLAdapter - Helper func designed to create and attach (but not start) // mysql adapter. Additionally this is a DRY attempt to make sure code is as organized // as possible. func (bs *BridgeService) AttachSQLAdapter(n string, c map[string]interface{}) (err error) { bs.Info("Setting up (service: %s) mysql database (adapter: %s)...", bs.Name(), n) var adapter mysql.Adapter if adapter, err = mysql.NewAdapter(n, c, bs.Logger); err != nil { return } bs.Connections.Attach(adapter.Name(), adapter) return }