mirror of https://github.com/go-gorm/gorm.git
Rename some interfaces
This commit is contained in:
parent
c9d5667ff0
commit
85109e104e
10
chain.go
10
chain.go
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
type Chain struct {
|
||||
d *DB
|
||||
db sql_common
|
||||
db sqlCommon
|
||||
value interface{}
|
||||
debug_mode bool
|
||||
|
||||
|
@ -228,9 +228,9 @@ func (s *Chain) Related(value interface{}, foreign_keys ...string) *Chain {
|
|||
}
|
||||
|
||||
func (s *Chain) Begin() *Chain {
|
||||
if db, ok := s.db.(sql_db); ok {
|
||||
if db, ok := s.db.(sqlDb); ok {
|
||||
tx, err := db.Begin()
|
||||
s.db = interface{}(tx).(sql_common)
|
||||
s.db = interface{}(tx).(sqlCommon)
|
||||
s.err(err)
|
||||
} else {
|
||||
s.err(errors.New("Can't start a transaction."))
|
||||
|
@ -245,7 +245,7 @@ func (s *Chain) Debug() *Chain {
|
|||
}
|
||||
|
||||
func (s *Chain) Commit() *Chain {
|
||||
if db, ok := s.db.(sql_tx); ok {
|
||||
if db, ok := s.db.(sqlTx); ok {
|
||||
s.err(db.Commit())
|
||||
} else {
|
||||
s.err(errors.New("Commit is not supported, no database transaction found."))
|
||||
|
@ -254,7 +254,7 @@ func (s *Chain) Commit() *Chain {
|
|||
}
|
||||
|
||||
func (s *Chain) Rollback() *Chain {
|
||||
if db, ok := s.db.(sql_tx); ok {
|
||||
if db, ok := s.db.(sqlTx); ok {
|
||||
s.err(db.Rollback())
|
||||
} else {
|
||||
s.err(errors.New("Rollback is not supported, no database transaction found."))
|
||||
|
|
8
do.go
8
do.go
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
type Do struct {
|
||||
chain *Chain
|
||||
db sql_common
|
||||
db sqlCommon
|
||||
guessedTableName string
|
||||
specifiedTableName string
|
||||
startedTransaction bool
|
||||
|
@ -711,9 +711,9 @@ func (s *Do) autoMigrate() *Do {
|
|||
}
|
||||
|
||||
func (s *Do) begin() *Do {
|
||||
if db, ok := s.db.(sql_db); ok {
|
||||
if db, ok := s.db.(sqlDb); ok {
|
||||
if tx, err := db.Begin(); err == nil {
|
||||
s.db = interface{}(tx).(sql_common)
|
||||
s.db = interface{}(tx).(sqlCommon)
|
||||
s.startedTransaction = true
|
||||
}
|
||||
}
|
||||
|
@ -722,7 +722,7 @@ func (s *Do) begin() *Do {
|
|||
|
||||
func (s *Do) commit_or_rollback() {
|
||||
if s.startedTransaction {
|
||||
if db, ok := s.db.(sql_tx); ok {
|
||||
if db, ok := s.db.(sqlTx); ok {
|
||||
if s.chain.hasError() {
|
||||
db.Rollback()
|
||||
} else {
|
||||
|
|
4
main.go
4
main.go
|
@ -11,7 +11,7 @@ func init() {
|
|||
}
|
||||
|
||||
type DB struct {
|
||||
db sql_common
|
||||
db sqlCommon
|
||||
dialect dialect.Dialect
|
||||
logger Logger
|
||||
logMode bool
|
||||
|
@ -24,7 +24,7 @@ func Open(driver, source string) (db DB, err error) {
|
|||
}
|
||||
|
||||
func (s *DB) SetPool(n int) {
|
||||
if db, ok := s.db.(sql_db); ok {
|
||||
if db, ok := s.db.(sqlDb); ok {
|
||||
db.SetMaxIdleConns(n)
|
||||
}
|
||||
}
|
||||
|
|
6
sql.go
6
sql.go
|
@ -2,19 +2,19 @@ package gorm
|
|||
|
||||
import "database/sql"
|
||||
|
||||
type sqlcommon interface {
|
||||
type sqlCommon interface {
|
||||
Exec(query string, args ...interface{}) (sql.Result, error)
|
||||
Prepare(query string) (*sql.Stmt, error)
|
||||
Query(query string, args ...interface{}) (*sql.Rows, error)
|
||||
QueryRow(query string, args ...interface{}) *sql.Row
|
||||
}
|
||||
|
||||
type sql_db interface {
|
||||
type sqlDb interface {
|
||||
Begin() (*sql.Tx, error)
|
||||
SetMaxIdleConns(n int)
|
||||
}
|
||||
|
||||
type sql_tx interface {
|
||||
type sqlTx interface {
|
||||
Commit() error
|
||||
Rollback() error
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue