Fixed issue https://github.com/jinzhu/gorm/issues/151 where postgresql connection problems fail silently

This commit is contained in:
Pär Karlsson 2015-07-28 16:29:56 +02:00
parent 82d726bbfd
commit bb8e0a9d84

View File

@ -59,6 +59,13 @@ func Open(dialect string, args ...interface{}) (DB, error) {
driver = "postgres" // FoundationDB speaks a postgres-compatible protocol. driver = "postgres" // FoundationDB speaks a postgres-compatible protocol.
} }
dbSql, err = sql.Open(driver, source) dbSql, err = sql.Open(driver, source)
// For some reason, postgres does not throw an connection error.
// Sending a ping request after the connection is made is a quick workaround for this
if driver == "postgres" && err != nil {
err = db.DB().Ping()
}
case sqlCommon: case sqlCommon:
source = reflect.Indirect(reflect.ValueOf(value)).FieldByName("dsn").String() source = reflect.Indirect(reflect.ValueOf(value)).FieldByName("dsn").String()
dbSql = value dbSql = value