txn_mongo

package module
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute[Stmt StmtHolder, D Doer[Stmt]](
	ctx context.Context, mod Module[Stmt], do D,
	fn txn.DoFunc[Options, Beginner, D], setters ...txn.DoerFieldSetter,
) (D, error)

func ExecuteOnce

func ExecuteOnce[D txn.Doer[Options, Beginner]](
	ctx context.Context, beginner Beginner, do D, fn txn.DoFunc[Options, Beginner, D]) (D, error)

ExecuteOnce executes a pgx transaction.

func Ping

func Ping(beginner Beginner, limit int, count txn.PingCount) (int, error)

Ping performs a ping operation.

Types

type Beginner

type Beginner = *mongo.Client

Beginner is an alias for *pgxpool.Pool.

type Doer

type Doer[T any] interface {
	txn.Doer[Options, Beginner]
	DefaultSetters(title string) []txn.DoerFieldSetter
	Client() T
	SetClient(T)
}

Doer defines the interface for PGX transaction operations.

type DoerBase

type DoerBase[T any] struct {
	txn.DoerBase[Options, Beginner]
	// contains filtered or unexported fields
}

DoerBase provides a base implementation for the Doer interface.

func (*DoerBase[T]) Client

func (do *DoerBase[T]) Client() T

Client returns the client.

func (*DoerBase[_]) DefaultSetters

func (do *DoerBase[_]) DefaultSetters(title string) []txn.DoerFieldSetter

func (*DoerBase[T]) SetClient

func (do *DoerBase[T]) SetClient(value T)

SetClient sets the client.

type MgoOptions

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

type Module

type Module[Stmt StmtHolder] interface {
	Beginner() Beginner
}

type ModuleBase

type ModuleBase[Stmt StmtHolder] struct {
	// contains filtered or unexported fields
}

func (*ModuleBase[_]) Beginner

func (b *ModuleBase[_]) Beginner() Beginner

func (*ModuleBase[_]) Init

func (b *ModuleBase[_]) Init(beginner Beginner)

type Options

type Options = *MgoOptions

Options is an alias for *pgx.TxOptions.

type StmtHolder

type StmtHolder = any

type Txn

type Txn struct {
	Raw mongo.Session
	// contains filtered or unexported fields
}

Txn wraps a raw pgx.Tx transaction.

func BeginTxn

func BeginTxn(ctx context.Context, _ Beginner, opt Options) (*Txn, error)

BeginTxn begins a pgx transaction.

func (*Txn) Commit

func (w *Txn) Commit(ctx context.Context) error

Commit commits the transaction.

func (*Txn) Rollback

func (w *Txn) Rollback(ctx context.Context) error

Rollback rolls back the transaction.

Jump to

Keyboard shortcuts

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