expose db.New as API

This commit is contained in:
Jinzhu 2015-01-06 15:11:41 +08:00
parent 1b4490fd47
commit 3500dfa1b6
3 changed files with 8 additions and 8 deletions

View File

@ -77,6 +77,11 @@ func (s *DB) DB() *sql.DB {
return s.db.(*sql.DB)
}
func (s *DB) New() *DB {
s.search = nil
return s.clone()
}
// Return the underlying sql.DB or sql.Tx instance.
// Use of this method is discouraged. It's mainly intended to allow
// coexistence with legacy non-GORM code.

View File

@ -22,11 +22,6 @@ func (s *DB) clone() *DB {
return &db
}
func (s *DB) new() *DB {
s.search = nil
return s.clone()
}
func (s *DB) err(err error) error {
if err != nil {
if err != RecordNotFound {

View File

@ -55,7 +55,7 @@ func (scope *Scope) New(value interface{}) *Scope {
// NewDB create a new DB without search information
func (scope *Scope) NewDB() *DB {
return scope.db.new()
return scope.db.New()
}
// DB get *sql.DB
@ -191,13 +191,13 @@ func (scope *Scope) CallMethod(name string) {
case func(s *Scope):
f(scope)
case func(s *DB):
f(scope.db.new())
f(scope.db.New())
case func() error:
scope.Err(f())
case func(s *Scope) error:
scope.Err(f(scope))
case func(s *DB) error:
scope.Err(f(scope.db.new()))
scope.Err(f(scope.db.New()))
default:
scope.Err(errors.New(fmt.Sprintf("unsupported function %v", name)))
}