dbcontext

package
v0.0.0-...-0b42950 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package dbcontext provides DB transaction support for transactions tha span method calls of multiple repositories and services.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB represents a DB connection that can be used to run SQL queries.

func New

func New(db *dbx.DB) *DB

New returns a new DB connection that wraps the given dbx.DB instance.

func (*DB) DB

func (db *DB) DB() *dbx.DB

DB returns the dbx.DB wrapped by this object.

func (*DB) TransactionHandler

func (db *DB) TransactionHandler() routing.Handler

TransactionHandler returns a middleware that starts a transaction. The transaction started is kept in the context and can be accessed via With().

func (*DB) Transactional

func (db *DB) Transactional(ctx context.Context, f func(ctx context.Context) error) error

Transactional starts a transaction and calls the given function with a context storing the transaction. The transaction associated with the context can be accesse via With().

func (*DB) With

func (db *DB) With(ctx context.Context) dbx.Builder

With returns a Builder that can be used to build and execute SQL queries. With will return the transaction if it is found in the given context. Otherwise it will return a DB connection associated with the context.

type TransactionFunc

type TransactionFunc func(ctx context.Context, f func(ctx context.Context) error) error

TransactionFunc represents a function that will start a transaction and run the given function.

Jump to

Keyboard shortcuts

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