github.com/Goboolean/common@v0.0.0-20231130153141-cb54596b217d/pkg/rdbms/transaction.go (about)

     1  package rdbms
     2  
     3  import (
     4  	"context"
     5  	"database/sql"
     6  
     7  	"github.com/Goboolean/common/pkg/resolver"
     8  )
     9  
    10  type Transaction struct {
    11  	tx  *sql.Tx
    12  	ctx context.Context
    13  }
    14  
    15  func (d *Transaction) Commit() error {
    16  	return d.tx.Commit()
    17  }
    18  
    19  func (d *Transaction) Rollback() error {
    20  	return d.tx.Rollback()
    21  }
    22  
    23  func (d *Transaction) Context() context.Context {
    24  	return d.ctx
    25  }
    26  
    27  func (d *Transaction) Transaction() interface{} {
    28  	return d.tx
    29  }
    30  
    31  func NewTransaction(tx *sql.Tx, ctx context.Context) resolver.Transactioner {
    32  	return &Transaction{tx: tx, ctx: ctx}
    33  }