transactional

package module
v0.0.0-...-ed4a795 Latest Latest
Warning

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

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

README

transactional

Provides a sqlx transaction wrapper for http.Handler.

Documentation

Overview

Package transactional provides sqlx transactional wrappers for http handlers and functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler interface {
	ServeHTTP(tx *sqlx.Tx, w http.ResponseWriter, r *http.Request) error
}

Handler is a HTTP handler that takes a transaction and might error.

type HandlerFunc

type HandlerFunc func(tx *sqlx.Tx, w http.ResponseWriter, r *http.Request) error

HandlerFunc is Handler function.

func (HandlerFunc) ServeHTTP

func (f HandlerFunc) ServeHTTP(tx *sqlx.Tx, w http.ResponseWriter, r *http.Request) error

ServeHTTP satisfies Handler.

type Transactional

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

Transactional can wrap functions and http handlers within a transaction.

func WithDB

func WithDB(db *sqlx.DB) *Transactional

WithDB creates a new transactional using the given db.

func (*Transactional) Wrap

Wrap wraps the given http handler within a transaction.

func (*Transactional) WrapF

WrapF wraps the given http handler func within a transaction.

func (*Transactional) WrapFn

func (t *Transactional) WrapFn(ctx context.Context, fn func(tx *sqlx.Tx) error) error

WrapFn wraps a function within a transaction.

type Typed

type Typed[T any] struct {
	// contains filtered or unexported fields
}

Typed can wrap functions into transactions.

func WithDBAndType

func WithDBAndType[T any](db *sqlx.DB) *Typed[T]

WithDBAndType() creates a new Typed using the given db and type.

func (*Typed[T]) WrapFn

func (t *Typed[T]) WrapFn(
	ctx context.Context,
	fn func(tx *sqlx.Tx) (T, error),
) (T, error)

WrapFn wraps a function within a transaction.

Jump to

Keyboard shortcuts

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