Skip to content

Commit 524dde0

Browse files
committed
Add ExecuteTx
1 parent 57d376c commit 524dde0

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

echo/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"context"
55
"database/sql"
66
"encoding/json"
7+
"errors"
78
q "github.com/core-go/sql"
89
"github.com/labstack/echo/v4"
9-
"github.com/pkg/errors"
1010
"net/http"
1111
"strconv"
1212
"time"

echo_v3/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"context"
55
"database/sql"
66
"encoding/json"
7+
"errors"
78
q "github.com/core-go/sql"
89
"github.com/labstack/echo"
9-
"github.com/pkg/errors"
1010
"net/http"
1111
"strconv"
1212
"time"

exec.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ func CallbackTx(ctx context.Context, db *sql.DB, callback func(ctx2 context.Cont
108108
err = tx.Commit()
109109
return err
110110
}
111+
func ExecuteTx(ctx context.Context, db *sql.DB, callback func(context.Context)(int64, error), opts ...*sql.TxOptions) (int64, error) {
112+
var res int64
113+
er0 := CallbackTx(ctx, db, func(ctx2 context.Context) error {
114+
result, err := callback(ctx)
115+
if err != nil {
116+
return err
117+
}
118+
res = result
119+
return nil
120+
}, opts...)
121+
return res, er0
122+
}
111123
func ExecuteAll(ctx context.Context, db *sql.DB, stmts ...Statement) (int64, error) {
112124
if stmts == nil || len(stmts) == 0 {
113125
return 0, nil

0 commit comments

Comments
 (0)