From e3c6bfd745640d0c37c5a98e935b13f3221d70c0 Mon Sep 17 00:00:00 2001 From: Alex Grintsvayg Date: Wed, 23 Aug 2017 16:59:29 -0400 Subject: [PATCH] use interface to enable custom Tx types --- boil/db.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/boil/db.go b/boil/db.go index 84bc7d3..b94c202 100644 --- a/boil/db.go +++ b/boil/db.go @@ -19,6 +19,11 @@ type Transactor interface { // Beginner begins transactions. type Beginner interface { + Begin() (Transactor, error) +} + +// SQLBeginner begins transactions (non-interface return type) +type SQLBeginner interface { Begin() (*sql.Tx, error) } @@ -26,7 +31,11 @@ type Beginner interface { 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()