forked from mirror/gorm
Refactor reuse existing database connection
This commit is contained in:
parent
1d6b59f223
commit
a4e0ef6509
6
main.go
6
main.go
|
@ -56,11 +56,7 @@ func Open(dialect string, args ...interface{}) (DB, error) {
|
||||||
}
|
}
|
||||||
dbSql, err = sql.Open(driver, source)
|
dbSql, err = sql.Open(driver, source)
|
||||||
case sqlCommon:
|
case sqlCommon:
|
||||||
if reflect.TypeOf(value).Kind() == reflect.Ptr {
|
source = reflect.Indirect(reflect.ValueOf(value)).FieldByName("dsn").String()
|
||||||
source = reflect.ValueOf(value).Elem().FieldByName("dsn").String()
|
|
||||||
} else {
|
|
||||||
source = reflect.ValueOf(value).FieldByName("dsn").String()
|
|
||||||
}
|
|
||||||
dbSql = value
|
dbSql = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
|
|
||||||
_ "github.com/denisenkom/go-mssqldb"
|
_ "github.com/denisenkom/go-mssqldb"
|
||||||
testdb "github.com/erikstmartin/go-testdb"
|
testdb "github.com/erikstmartin/go-testdb"
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
"github.com/jinzhu/now"
|
"github.com/jinzhu/now"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
@ -567,7 +567,6 @@ func TestOpenExistingDB(t *testing.T) {
|
||||||
if db.Where("name = ?", "jnfeinstein").First(&user).Error == gorm.RecordNotFound {
|
if db.Where("name = ?", "jnfeinstein").First(&user).Error == gorm.RecordNotFound {
|
||||||
t.Errorf("Should have found existing record")
|
t.Errorf("Should have found existing record")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkGorm(b *testing.B) {
|
func BenchmarkGorm(b *testing.B) {
|
||||||
|
|
Loading…
Reference in New Issue