use interface to enable custom Tx types
This commit is contained in:
parent
86c580f537
commit
e3c6bfd745
1 changed files with 10 additions and 1 deletions
11
boil/db.go
11
boil/db.go
|
@ -19,6 +19,11 @@ type Transactor interface {
|
||||||
|
|
||||||
// Beginner begins transactions.
|
// Beginner begins transactions.
|
||||||
type Beginner interface {
|
type Beginner interface {
|
||||||
|
Begin() (Transactor, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SQLBeginner begins transactions (non-interface return type)
|
||||||
|
type SQLBeginner interface {
|
||||||
Begin() (*sql.Tx, error)
|
Begin() (*sql.Tx, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +31,11 @@ type Beginner interface {
|
||||||
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…
Reference in a new issue