From 1facaad1a16a3e28abd18602104db7b104c37676 Mon Sep 17 00:00:00 2001 From: brucehuang Date: Tue, 9 Jul 2019 08:16:20 +0800 Subject: [PATCH] Update wrapper.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 把判空提前,避免空指针错误 --- wrapper.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wrapper.go b/wrapper.go index a946c58..705e206 100644 --- a/wrapper.go +++ b/wrapper.go @@ -210,10 +210,10 @@ func (w *Wrapper) Select(dest interface{}, query string, args ...interface{}) (e func (w *Wrapper) Txx(ctx context.Context, fn func(ctx context.Context, tx *sqlx.Tx) error) (err error) { db := DB(w.database) tx, err := db.BeginTxx(ctx, nil) - tx = tx.Unsafe() if err != nil { return err } + tx = tx.Unsafe() defer func() { if err != nil { err := tx.Rollback() @@ -234,10 +234,10 @@ func (w *Wrapper) Txx(ctx context.Context, fn func(ctx context.Context, tx *sqlx func (w *Wrapper) Tx(fn func(tx *sqlx.Tx) error) (err error) { db := DB(w.database) tx, err := db.Beginx() - tx = tx.Unsafe() if err != nil { return err } + tx = tx.Unsafe() defer func() { if err != nil { err := tx.Rollback()