storeutil

package
v0.0.0-...-269d6e4 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxWithTx

func CtxWithTx(ctx context.Context, db *sql.DB, opts ...TxOptions) (context.Context, error)

CtxWithTx attach a database transaction to the context. It returns the context unchanged if there's error starting the transaction.

func FinishTxForCtx

func FinishTxForCtx(ctx context.Context, err error) error

FinishTxForCtx commits or rolls back the transaction attatched to the context depending on the error passed in and returns the result. It errors if the context doesn't have a transaction attached.

func MigrateAndConnectToDB

func MigrateAndConnectToDB(postgresURI string, as *bindata.AssetSource) (*sql.DB, error)

MigrateAndConnectToDB run db migrations and return a ready to use connection to the Postgres database.

func TxReadonly

func TxReadonly() func(o *sql.TxOptions) *sql.TxOptions

TxReadonly signals the DB driver that the transaction is read-only.

func TxWithIsolation

func TxWithIsolation(level sql.IsolationLevel) func(o *sql.TxOptions) *sql.TxOptions

TxWithIsolation tells the DB driver the isolation level of the transaction.

func WithCtxTx

func WithCtxTx(ctx context.Context, withTx func(*sql.Tx) error, noTx func() error) error

WithCtxTx calls withTx if a transaction is attached to the context, or calls noTx.

func WithTx

func WithTx(ctx context.Context, db *sql.DB, f func(*sql.Tx) error, opts ...TxOptions) (err error)

WithTx runs the provided closure in a transaction. Then transaction is committed if the closure returns no error, and rolled back otherwise. When a transaction is already attached to the context, it is used instead and no automatical commit or rollback happens.

Types

type TxOptions

type TxOptions func(o *sql.TxOptions) *sql.TxOptions

TxOptions allows the caller of CtxTxWraper.CtxWithTx to control various options to the transaction.

Jump to

Keyboard shortcuts

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