Allow open to take transaction.

Need to skip the ping, otherwise results in a nil dereference.
This commit is contained in:
Emil Davtyan 2017-04-06 15:55:36 +02:00
parent 45ccb13437
commit 5ed4c3f290
1 changed files with 7 additions and 5 deletions

10
main.go
View File

@ -71,11 +71,13 @@ func Open(dialect string, args ...interface{}) (db *DB, err error) {
dialect: newDialect(dialect, dbSQL),
}
db.parent = db
if err == nil {
if err != nil {
return
}
// Send a ping to make sure the database connection is alive.
if err = db.DB().Ping(); err != nil {
db.DB().Close()
if d, ok := dbSQL.(*sql.DB); ok {
if err = d.Ping(); err != nil {
d.Close()
}
}
return