sqlxhelper

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithTransaction

func WithTransaction(ctx context.Context, opt *sql.TxOptions, db *sqlx.DB, fn ...TxFn) error

WithTransaction execute [1...n] TxFn used one transaction The provided context is used until the transaction is committed or rolled back. If the context is canceled, the sql package will roll back the transaction. Tx.Commit will return an error if the context is canceled. TxOptions holds the transaction options to be used in DB.BeginTx.

Types

type TxFn

type TxFn = func(*sqlx.Tx) 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.

func InsertAndGetLastID

func InsertAndGetLastID(ctx context.Context, lastInsertID *int64, query string, args ...interface{}) TxFn

Usefully for sql query like this query := `INSERT INTO table (col1, col2) VALUES ($1, $2) RETURNING id`

Jump to

Keyboard shortcuts

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