transactions

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2024 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTransaction

func WithTransaction(db *sql.DB, fn TxFn) (err error)

WithTransaction creates a new transaction and handles rollback/commit based on the error object returned by the `TxFn`

Types

type Transaction

type Transaction interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Transaction is an interface that models the standard transaction in `database/sql`. To ensure `TxFn` funcs cannot commit or rollback a transaction (which is handled by `WithTransaction`), those methods are not included here.

type TxFn

type TxFn func(Transaction) error

TxFn is a function that will be called with an initialized `Transaction` object that can be used for executing statements and queries against a database.

Jump to

Keyboard shortcuts

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