sqlutils

package
v0.0.0-...-b3f093e Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package sqlutils contains functionality to wrap existing database functionality

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTransaction

func WithTransaction(ctx context.Context, txPrep TransactionPreparer, txFunc func(*sqlx.Tx) error) error

WithTransaction is used for transactions that are execution only (i.e., no return value) and only returns an error

func WithTransactionRet

func WithTransactionRet[T any](ctx context.Context, txPrep TransactionPreparer, txFunc func(*sqlx.Tx) (T, error)) (result T, txErr error)

WithTransactionRet is a wrapper function which handles creating, committing or rolling back a transaction If there are any errors when executing the txFunc, the tx is rolled back. Otherwise, the tx is committed. We use named return parameters here so that the deferred function can access and reassign the variables

Types

type NamedPreparer

type NamedPreparer interface {
	PrepareNamed(query string) (*sqlx.NamedStmt, error)
}

NamedPreparer is an interface used by to execute a sqlx transaction either directly or as a transacation.

type TransactionPreparer

type TransactionPreparer interface {
	Beginx() (*sqlx.Tx, error)
}

TransactionPreparer is an interface used to initiate a sqlx.TX

Jump to

Keyboard shortcuts

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