allow generic interface or real sql tx

This commit is contained in:
Alex Grintsvayg 2017-09-02 11:52:31 -04:00
parent cd445bf2f4
commit 0b0a1f21c2

View file

@ -22,11 +22,19 @@ 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 {
panic("database does not support transactions")
creator2, ok2 := currentDB.(SQLBeginner)
if !ok2 {
panic("database does not support transactions")
}
return creator2.Begin()
}
return creator.Begin()