github.com/ydb-platform/ydb-go-sdk/v3@v3.89.2/internal/tx/transaction.go (about) 1 package tx 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors" 8 ) 9 10 type Transaction interface { 11 Identifier 12 UnLazy(ctx context.Context) error 13 SessionID() string 14 15 // OnBeforeCommit add callback, which will be called before commit transaction 16 // the method will be not call the method if some error happen and transaction will not be committed 17 OnBeforeCommit(f OnTransactionBeforeCommit) 18 OnCompleted(f OnTransactionCompletedFunc) 19 Rollback(ctx context.Context) error 20 } 21 22 type ( 23 OnTransactionBeforeCommit func(ctx context.Context) error 24 OnTransactionCompletedFunc func(transactionResult error) 25 ) 26 27 func AsTransaction(id Identifier) (Transaction, error) { 28 if t, ok := id.(Transaction); ok { 29 return t, nil 30 } 31 32 return nil, xerrors.WithStackTrace(xerrors.Wrap(fmt.Errorf( 33 "waiting transaction object of type query.Transaction, got: %T", 34 id, 35 ))) 36 }