From 5ed4c3f2908ed79bb7acf0080826db18e0ef46ce Mon Sep 17 00:00:00 2001 From: Emil Davtyan Date: Thu, 6 Apr 2017 15:55:36 +0200 Subject: [PATCH] Allow open to take transaction. Need to skip the ping, otherwise results in a nil dereference. --- main.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 9ae560a1..047baed2 100644 --- a/main.go +++ b/main.go @@ -71,11 +71,13 @@ func Open(dialect string, args ...interface{}) (db *DB, err error) { dialect: newDialect(dialect, dbSQL), } db.parent = db - - if err == nil { - // Send a ping to make sure the database connection is alive. - if err = db.DB().Ping(); err != nil { - db.DB().Close() + if err != nil { + return + } + // Send a ping to make sure the database connection is alive. + if d, ok := dbSQL.(*sql.DB); ok { + if err = d.Ping(); err != nil { + d.Close() } } return