Return pointer when Open

This commit is contained in:
Jinzhu 2016-01-10 21:26:55 +08:00
parent 84942c60b8
commit f574429f5e
2 changed files with 4 additions and 4 deletions

View File

@ -36,7 +36,7 @@ type DB struct {
joinTableHandlers map[string]JoinTableHandler joinTableHandlers map[string]JoinTableHandler
} }
func Open(dialect string, args ...interface{}) (DB, error) { func Open(dialect string, args ...interface{}) (*DB, error) {
var db DB var db DB
var err error var err error
@ -79,7 +79,7 @@ func Open(dialect string, args ...interface{}) (DB, error) {
} }
} }
return db, err return &db, err
} }
func (s *DB) Close() error { func (s *DB) Close() error {

View File

@ -20,7 +20,7 @@ import (
) )
var ( var (
DB gorm.DB DB *gorm.DB
t1, t2, t3, t4, t5 time.Time t1, t2, t3, t4, t5 time.Time
) )
@ -41,7 +41,7 @@ func init() {
runMigration() runMigration()
} }
func OpenTestConnection() (db gorm.DB, err error) { func OpenTestConnection() (db *gorm.DB, err error) {
switch os.Getenv("GORM_DIALECT") { switch os.Getenv("GORM_DIALECT") {
case "mysql": case "mysql":
// CREATE USER 'gorm'@'localhost' IDENTIFIED BY 'gorm'; // CREATE USER 'gorm'@'localhost' IDENTIFIED BY 'gorm';