db

package
v0.0.0-...-40c8b04 Latest Latest
Warning

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

Go to latest
Published: May 4, 2021 License: BSD-2-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTransaction

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

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

Types

type DB

type DB = sqlx.DB

func NewDB

func NewDB(driverName, connString string) (*DB, error)

NewDB returns connected Client

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

A 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