Skip to content

Commit 0f3b78b

Browse files
committed
sqlcmig6: add transaction executor for Queries
This commit adds a helper struct that creates a `sqldb/v2` transaction executor that wraps the `sqlcmig6.Queries` type.
1 parent 0355557 commit 0f3b78b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

db/sqlcmig6/db.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package sqlcmig6
33
import (
44
"context"
55
"database/sql"
6+
"github.com/lightningnetwork/lnd/sqldb/v2"
67
)
78

89
type DBTX interface {
@@ -25,3 +26,23 @@ func (q *Queries) WithTx(tx *sql.Tx) *Queries {
2526
db: tx,
2627
}
2728
}
29+
30+
type TxExecutor[T sqldb.BaseQuerier] struct {
31+
*sqldb.TransactionExecutor[T]
32+
33+
*Queries
34+
}
35+
36+
func NewTxExecutor(baseDB *sqldb.BaseDB,
37+
queries *Queries) *TxExecutor[*Queries] {
38+
39+
executor := sqldb.NewTransactionExecutor(
40+
baseDB, func(tx *sql.Tx) *Queries {
41+
return queries.WithTx(tx)
42+
},
43+
)
44+
return &TxExecutor[*Queries]{
45+
TransactionExecutor: executor,
46+
Queries: queries,
47+
}
48+
}

0 commit comments

Comments
 (0)