Documentation
¶
Overview ¶
Package database provides database agnostic helpers.
Index ¶
- Variables
- func WrapInSyncTx[TTx MinimalDBTx, TResult any](ctx context.Context, tx *SyncTx[TTx], ...) (TResult, error)
- func WrapInSyncTxNoError[TTx MinimalDBTx, TResult any](ctx context.Context, tx *SyncTx[TTx], ...) TResult
- func WrapInSyncTxNoReturn[TTx MinimalDBTx](ctx context.Context, tx *SyncTx[TTx], queryFunc func(ctx context.Context))
- func WrapWithSpan[T any](ctx context.Context, dbName string, ...) (T, error)
- func WrapWithSpanNoError[T any](ctx context.Context, dbName string, ...) T
- type MinimalDBTx
- type SyncTx
Constants ¶
This section is empty.
Variables ¶
var ( // ErrResourceNotFound is an error with value "resource not found". ErrResourceNotFound = errors.New("resource not found") // ErrResourceConflict is an error with value "resource unique value already used". ErrResourceConflict = errors.New("resource conflicts with existing resource") )
Functions ¶
func WrapInSyncTx ¶
func WrapInSyncTx[TTx MinimalDBTx, TResult any]( ctx context.Context, tx *SyncTx[TTx], queryFunc func(ctx context.Context) (TResult, error), ) (TResult, error)
WrapInSyncTx is used to make sure a transactional database action can run concurrently.
func WrapInSyncTxNoError ¶
func WrapInSyncTxNoError[TTx MinimalDBTx, TResult any]( ctx context.Context, tx *SyncTx[TTx], queryFunc func(ctx context.Context) TResult, ) TResult
WrapInSyncTxNoError is used to make sure a transactional database action can run concurrently. The executed database action shouldn't return an error.
func WrapInSyncTxNoReturn ¶
func WrapInSyncTxNoReturn[TTx MinimalDBTx]( ctx context.Context, tx *SyncTx[TTx], queryFunc func(ctx context.Context), )
WrapInSyncTxNoReturn is used to make sure a transactional database action can run concurrently. The executed database action shouldn't return anything.
func WrapWithSpan ¶
func WrapWithSpan[T any]( ctx context.Context, dbName string, queryFunc func(ctx context.Context, sql string, args ...any) (T, error), sql string, args ...any) (T, error)
WrapWithSpan is used to wrap a database action in a sentry.Span.
func WrapWithSpanNoError ¶
func WrapWithSpanNoError[T any]( ctx context.Context, dbName string, queryFunc func(ctx context.Context, sql string, args ...any) T, sql string, args ...any) T
WrapWithSpanNoError is used to wrap a database action in a sentry.Span. The executed database action shouldn't return an error.
Types ¶
type MinimalDBTx ¶
MinimalDBTx is the minimal interface a DB transaction should implement.
type SyncTx ¶
type SyncTx[TTx MinimalDBTx] struct { sync.Mutex Tx TTx }
SyncTx wraps a database transaction to make sure it can be used concurrently. This is achieved by locking the transaction when in use.
func CreateSyncTx ¶
func CreateSyncTx[TTx MinimalDBTx]( ctx context.Context, beginTxFunc func(ctx context.Context) (TTx, error), ) *SyncTx[TTx]
CreateSyncTx creates a SyncTx which makes sure a database transaction can be used concurrently.