mirror of https://github.com/go-gorm/gorm.git
expose db.New as API
This commit is contained in:
parent
1b4490fd47
commit
3500dfa1b6
5
main.go
5
main.go
|
@ -77,6 +77,11 @@ func (s *DB) DB() *sql.DB {
|
||||||
return s.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.
|
// Return the underlying sql.DB or sql.Tx instance.
|
||||||
// Use of this method is discouraged. It's mainly intended to allow
|
// Use of this method is discouraged. It's mainly intended to allow
|
||||||
// coexistence with legacy non-GORM code.
|
// coexistence with legacy non-GORM code.
|
||||||
|
|
|
@ -22,11 +22,6 @@ func (s *DB) clone() *DB {
|
||||||
return &db
|
return &db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) new() *DB {
|
|
||||||
s.search = nil
|
|
||||||
return s.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *DB) err(err error) error {
|
func (s *DB) err(err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != RecordNotFound {
|
if err != RecordNotFound {
|
||||||
|
|
6
scope.go
6
scope.go
|
@ -55,7 +55,7 @@ func (scope *Scope) New(value interface{}) *Scope {
|
||||||
|
|
||||||
// NewDB create a new DB without search information
|
// NewDB create a new DB without search information
|
||||||
func (scope *Scope) NewDB() *DB {
|
func (scope *Scope) NewDB() *DB {
|
||||||
return scope.db.new()
|
return scope.db.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
// DB get *sql.DB
|
// DB get *sql.DB
|
||||||
|
@ -191,13 +191,13 @@ func (scope *Scope) CallMethod(name string) {
|
||||||
case func(s *Scope):
|
case func(s *Scope):
|
||||||
f(scope)
|
f(scope)
|
||||||
case func(s *DB):
|
case func(s *DB):
|
||||||
f(scope.db.new())
|
f(scope.db.New())
|
||||||
case func() error:
|
case func() error:
|
||||||
scope.Err(f())
|
scope.Err(f())
|
||||||
case func(s *Scope) error:
|
case func(s *Scope) error:
|
||||||
scope.Err(f(scope))
|
scope.Err(f(scope))
|
||||||
case func(s *DB) error:
|
case func(s *DB) error:
|
||||||
scope.Err(f(scope.db.new()))
|
scope.Err(f(scope.db.New()))
|
||||||
default:
|
default:
|
||||||
scope.Err(errors.New(fmt.Sprintf("unsupported function %v", name)))
|
scope.Err(errors.New(fmt.Sprintf("unsupported function %v", name)))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue