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
10
boil/db.go
10
boil/db.go
|
@ -22,11 +22,19 @@ type Beginner interface {
|
||||||
Begin() (Transactor, error)
|
Begin() (Transactor, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SQLBeginner interface {
|
||||||
|
Begin() (*sql.Tx, error)
|
||||||
|
}
|
||||||
|
|
||||||
// Begin a transaction
|
// Begin a transaction
|
||||||
func Begin() (Transactor, error) {
|
func Begin() (Transactor, error) {
|
||||||
creator, ok := currentDB.(Beginner)
|
creator, ok := currentDB.(Beginner)
|
||||||
if !ok {
|
if !ok {
|
||||||
panic("database does not support transactions")
|
creator2, ok2 := currentDB.(SQLBeginner)
|
||||||
|
if !ok2 {
|
||||||
|
panic("database does not support transactions")
|
||||||
|
}
|
||||||
|
return creator2.Begin()
|
||||||
}
|
}
|
||||||
|
|
||||||
return creator.Begin()
|
return creator.Begin()
|
||||||
|
|
Loading…
Add table
Reference in a new issue