Skip to content

Commit

Permalink
Refactor reuse existing database connection
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhu committed Nov 25, 2014
1 parent 1d6b59f commit a4e0ef6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
6 changes: 1 addition & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ func Open(dialect string, args ...interface{}) (DB, error) {
}
dbSql, err = sql.Open(driver, source)
case sqlCommon:
if reflect.TypeOf(value).Kind() == reflect.Ptr {
source = reflect.ValueOf(value).Elem().FieldByName("dsn").String()
} else {
source = reflect.ValueOf(value).FieldByName("dsn").String()
}
source = reflect.Indirect(reflect.ValueOf(value)).FieldByName("dsn").String()
dbSql = value
}

Expand Down
3 changes: 1 addition & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

_ "github.com/denisenkom/go-mssqldb"
testdb "github.com/erikstmartin/go-testdb"
"github.com/jinzhu/gorm"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
"github.com/jinzhu/now"
_ "github.com/lib/pq"
_ "github.com/mattn/go-sqlite3"
Expand Down Expand Up @@ -567,7 +567,6 @@ func TestOpenExistingDB(t *testing.T) {
if db.Where("name = ?", "jnfeinstein").First(&user).Error == gorm.RecordNotFound {
t.Errorf("Should have found existing record")
}

}

func BenchmarkGorm(b *testing.B) {
Expand Down

0 comments on commit a4e0ef6

Please sign in to comment.