mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
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.
This commit is contained in:
parent
9442c58cc1
commit
01d9c2a724
1 changed files with 17 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ package sqlcmig6
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"github.com/lightningnetwork/lnd/sqldb/v2"
|
||||
)
|
||||
|
||||
type DBTX interface {
|
||||
|
|
@ -25,3 +26,19 @@ func (q *Queries) WithTx(tx *sql.Tx) *Queries {
|
|||
db: tx,
|
||||
}
|
||||
}
|
||||
|
||||
type TxExecutor struct {
|
||||
*sqldb.TransactionExecutor[*Queries]
|
||||
}
|
||||
|
||||
func NewTxExecutor(baseDB *sqldb.BaseDB, queries *Queries) *TxExecutor {
|
||||
executor := sqldb.NewTransactionExecutor(
|
||||
baseDB, func(tx *sql.Tx) *Queries {
|
||||
return queries.WithTx(tx)
|
||||
},
|
||||
)
|
||||
|
||||
return &TxExecutor{
|
||||
TransactionExecutor: executor,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue