mirror of https://github.com/go-gorm/gorm.git
Add method to close gorm db connection
This commit is contained in:
parent
8e3181494d
commit
fd3ce3b39a
8
main.go
8
main.go
|
@ -28,6 +28,10 @@ func Open(driver, source string) (DB, error) {
|
||||||
return db, err
|
return db, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *DB) Close() error {
|
||||||
|
return s.parent.db.(*sql.DB).Close()
|
||||||
|
}
|
||||||
|
|
||||||
func (s *DB) DB() *sql.DB {
|
func (s *DB) DB() *sql.DB {
|
||||||
return s.db.(*sql.DB)
|
return s.db.(*sql.DB)
|
||||||
}
|
}
|
||||||
|
@ -131,13 +135,13 @@ func (s *DB) Assign(attrs ...interface{}) *DB {
|
||||||
|
|
||||||
func (s *DB) First(out interface{}, where ...interface{}) *DB {
|
func (s *DB) First(out interface{}, where ...interface{}) *DB {
|
||||||
scope := s.clone().NewScope(out)
|
scope := s.clone().NewScope(out)
|
||||||
scope.Search = scope.Search.clone().order(scope.TableName()+"."+scope.PrimaryKey()).limit(1)
|
scope.Search = scope.Search.clone().order(scope.TableName() + "." + scope.PrimaryKey()).limit(1)
|
||||||
return scope.inlineCondition(where...).callCallbacks(s.parent.callback.queries).db
|
return scope.inlineCondition(where...).callCallbacks(s.parent.callback.queries).db
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DB) Last(out interface{}, where ...interface{}) *DB {
|
func (s *DB) Last(out interface{}, where ...interface{}) *DB {
|
||||||
scope := s.clone().NewScope(out)
|
scope := s.clone().NewScope(out)
|
||||||
scope.Search = scope.Search.clone().order(scope.TableName()+"."+scope.PrimaryKey() + " DESC").limit(1)
|
scope.Search = scope.Search.clone().order(scope.TableName() + "." + scope.PrimaryKey() + " DESC").limit(1)
|
||||||
return scope.inlineCondition(where...).callCallbacks(s.parent.callback.queries).db
|
return scope.inlineCondition(where...).callCallbacks(s.parent.callback.queries).db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,9 +7,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
|
|
||||||
"os"
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
Loading…
Reference in New Issue