Conn.Begin and Conn.BeginTx return a Tx interface

This is necessary for the Conn.Begin method to signature as other
methods that begin a transaction. This is technically a breaking change
but practically is just a bug fix that is extremely unlikely to break
any existing code.
pull/626/head
Jack Christensen 2019-10-12 09:01:18 -05:00
parent 931bae46a2
commit c0a1f9976a
2 changed files with 6 additions and 2 deletions

View File

@ -1,3 +1,7 @@
# Unreleased
* Conn.Begin and Conn.BeginTx return a Tx interface instead of the internal dbTx struct. This is necessary for the Conn.Begin method to signature as other methods that begin a transaction. This is technically a breaking change but practically is just a bug fix that is extremely unlikely to break any existing code.
# 4.0.1 (September 19, 2019)
* Fix statement cache cleanup.

4
tx.go
View File

@ -67,13 +67,13 @@ var ErrTxCommitRollback = errors.New("commit unexpectedly resulted in rollback")
// Begin starts a transaction. Unlike database/sql, the context only affects the begin command. i.e. there is no
// auto-rollback on context cancellation.
func (c *Conn) Begin(ctx context.Context) (*dbTx, error) {
func (c *Conn) Begin(ctx context.Context) (Tx, error) {
return c.BeginTx(ctx, TxOptions{})
}
// BeginTx starts a transaction with txOptions determining the transaction mode. Unlike database/sql, the context only
// affects the begin command. i.e. there is no auto-rollback on context cancellation.
func (c *Conn) BeginTx(ctx context.Context, txOptions TxOptions) (*dbTx, error) {
func (c *Conn) BeginTx(ctx context.Context, txOptions TxOptions) (Tx, error) {
_, err := c.Exec(ctx, txOptions.beginSQL())
if err != nil {
// begin should never fail unless there is an underlying connection issue or