transactionalmanager

package
v0.0.0-...-29e199f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FuncToExecuteAfterCommitType

type FuncToExecuteAfterCommitType func(context.Context) error

FuncToExecuteAfterCommitType callback function to execute after a database transaction commit

type TransactionalManager

type TransactionalManager struct {
	// contains filtered or unexported fields
}

TransactionalManager handles transactional functionality.

func ProvideTransactionalManager

func ProvideTransactionalManager(options TransactionalManagerOptions) *TransactionalManager

ProvideTransactionalManager creates a TransactionalManager object with given options.

func (*TransactionalManager) ExecuteInTransaction

func (t *TransactionalManager) ExecuteInTransaction(ctx context.Context, transactionalFunc func(context.Context) (interface{}, error)) (response interface{}, failure error)

ExecuteInTransaction begins the execution of a transaction and rollbacks (reverts) any persistent changes if the transaction fails. ctx determines the context to execute transaction within and transactionalFunc the transaction to perform. It returns transaction result as interface{} and it returns an usecase failure if fails.

func (*TransactionalManager) RegisterAfterCommitIfTransactionInProgress

func (t *TransactionalManager) RegisterAfterCommitIfTransactionInProgress(ctx context.Context, funcToExecuteAfterCommit FuncToExecuteAfterCommitType) bool

RegisterAfterCommitIfTransactionInProgress registers a callback function to execute after the database transaction in the provided context is committed

type TransactionalManagerOptions

type TransactionalManagerOptions struct {
	// TransactionalStorage transactional manager storage
	TransactionalStorage TransactionalStorage
}

TransactionalManagerOptions configures a TransactionalManager.

type TransactionalManagerUseCase

type TransactionalManagerUseCase interface {
	// ExecuteInTransaction executes a database transaction.
	ExecuteInTransaction(ctx context.Context, transactionalFunc func(context.Context) (interface{}, error)) (interface{}, error)
	// RegisterAfterCommitIfTransactionInProgress callback to execute after committing a database transaction.
	RegisterAfterCommitIfTransactionInProgress(ctx context.Context, funcToExecuteAfterCommit FuncToExecuteAfterCommitType) bool
}

TransactionalManagerUseCase defines the functionality to execute a transaction in a transactional manner.

type TransactionalStorage

type TransactionalStorage interface {
	// BeginTransaction starts a storage operation that is transactional. It returns an error if it fails
	BeginTransaction(ctx context.Context) (context.Context, error)
	// RollbackTransaction rollback to previous state a storage operation that is transactional. It returns an error if it fails
	RollbackTransaction(ctx context.Context) error
	// CommitTransaction confirms a storage operation that is transactional. It returns an error if it fails
	CommitTransaction(ctx context.Context) error
	// GetTransaction returns the transaction from context (in case of success).
	GetTransaction(ctx context.Context) (any, error)
}

TransactionalStorage defines a storage for transactional manager

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL