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