configure actual sql connections as they should be

This commit is contained in:
Tit Petric
2018-07-05 11:17:02 +02:00
parent 9eeffef679
commit 2892ef818d
5 changed files with 22 additions and 24 deletions
+4 -2
View File
@@ -60,12 +60,14 @@ func init() {
// be applied, and your custom settings will be honored.
func (r *DatabaseFactory) Add(name string, config interface{}) {
switch val := config.(type) {
case *string:
r.credentials[name] = &DatabaseCredential{DSN: *val}
case string:
r.credentials[name] = &DatabaseCredential{DSN: val}
case DatabaseCredential:
r.credentials[name] = &val
default:
panic("factory.Database.Add can take config as string|factory.DatabaseCredential")
panic("factory.Database.Add can take config as string|*string|factory.DatabaseCredential")
}
}
@@ -118,7 +120,7 @@ func (r *DatabaseFactory) Get(dbName ...string) (*DB, error) {
}
dsn, _ := r.GetDSN(name)
if dsn != "" {
handle, err := sqlx.Open("mysql", dsn)
handle, err := sqlx.Connect("mysql", dsn)
if err != nil {
return nil, err
}