stdent

package
v0.0.51 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package stdent provides re-usable code for using Ent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttemptFromContext added in v0.0.50

func AttemptFromContext(ctx context.Context) int

AttemptFromContext returns which execution attempt it is. Panics if this information is not present.

func ContextWithAttempts added in v0.0.50

func ContextWithAttempts(ctx context.Context, v int) context.Context

ContextWithAttempts stores which execution attempt it is.

func ContextWithTx added in v0.0.50

func ContextWithTx[T Tx](ctx context.Context, tx T) context.Context

ContextWithTx returns a context with the Tx in it.

func Transact0 added in v0.0.50

func Transact0[T Tx](
	ctx context.Context,
	txr *Transactor[T],
	fnc func(ctx context.Context, tx T) error,
) (err error)

Transact0 runs Transact1 but without a value to return.

func Transact1 added in v0.0.50

func Transact1[T Tx, U any](
	ctx context.Context,
	txr *Transactor[T],
	fnc func(ctx context.Context, tx T) (U, error),
) (res U, err error)

Transact1 runs fnc in a transaction T derived from the provided Ent client while returning one value of type U. The implementation is taken from the official docs: https://entgo.io/docs/transactions#best-practices. If the context already has a transaction, it runs it in that one.

func TxFromContext added in v0.0.50

func TxFromContext[T Tx](ctx context.Context) T

TxFromContext will get a transaction of type T from the context or panic.

Types

type Client added in v0.0.50

type Client[T Tx] interface {
	BeginTx(ctx context.Context, opts *entsql.TxOptions) (T, error)
}

Client defines an Ent client that begins transactions of type T.

type Option added in v0.0.50

type Option func(opts *options)

func IsolationLevel added in v0.0.50

func IsolationLevel(v sql.IsolationLevel) Option

IsolationLevel specifies the isolation level for new transactions.

func ReadOnly added in v0.0.50

func ReadOnly(v bool) Option

ReadOnly sets the transaction to be read-only.

func SerializationFailureCodes added in v0.0.50

func SerializationFailureCodes(v ...string) Option

SerializationFailureCodes configures which PostgreSQL error codes should be considered serialization failures.

func SerializationFailureMaxRetries added in v0.0.50

func SerializationFailureMaxRetries(v int) Option

SerializationFailureMaxRetries configures the maximum number of retries in case the transacted code encounters a serialization failure.

type Transactor added in v0.0.50

type Transactor[T Tx] struct {
	// contains filtered or unexported fields
}

func New added in v0.0.50

func New[T Tx](client Client[T], opts ...Option) *Transactor[T]

type Tx added in v0.0.50

type Tx interface {
	Commit() error
	Rollback() error
}

Tx describes the constraints for an Ent transaction.

Directories

Path Synopsis
Package stdenttest is a utility for writing tests on ent transaction.
Package stdenttest is a utility for writing tests on ent transaction.

Jump to

Keyboard shortcuts

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