allow generic interface or real sql tx
This commit is contained in:
parent
cd445bf2f4
commit
0b0a1f21c2
1 changed files with 9 additions and 1 deletions
|
@ -22,12 +22,20 @@ type Beginner interface {
|
|||
Begin() (Transactor, error)
|
||||
}
|
||||
|
||||
type SQLBeginner interface {
|
||||
Begin() (*sql.Tx, error)
|
||||
}
|
||||
|
||||
// Begin a transaction
|
||||
func Begin() (Transactor, error) {
|
||||
creator, ok := currentDB.(Beginner)
|
||||
if !ok {
|
||||
creator2, ok2 := currentDB.(SQLBeginner)
|
||||
if !ok2 {
|
||||
panic("database does not support transactions")
|
||||
}
|
||||
return creator2.Begin()
|
||||
}
|
||||
|
||||
return creator.Begin()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue