transact

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2019 License: MIT Imports: 2 Imported by: 0

README

travis ci status codecov status godoc Go Report Card

transact

A simple helper for executing SQL queries inside a transaction and automatically handling rollback and commit scenarios.

Example

err := transact.DoContext(ctx, db.DB, func(tx *sql.Tx) error {
    q := `SELECT ...` // any sql query that needs to run in a transaction

    _, err := tx.Exec(ctx, q, someID, count)
    if err != nil {
        return err // any errors will roll the transaction back before returning
    }

    panic("WHAT") // any panic will be recovered, roll the transaction back, and re-panic

    return nil // nil errors will commit the transaction
})
if err != nil {
    return err
}

Documentation

Overview

Package transact provides a simple helper for running sql queries inside a transaction without needing to handle all rollback and commit scenarios manually.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(db *sql.DB, txFunc func(*sql.Tx) error) (err error)

Do executes the given txFunc inside of a new transaction handling all possible rollback and commit scenarios.

func DoContext added in v0.0.2

func DoContext(ctx context.Context, db *sql.DB, txFunc func(*sql.Tx) error) (err error)

DoContext executes the given txFunc inside of a new transaction handling all possible rollback and commit scenarios.

Types

This section is empty.

Jump to

Keyboard shortcuts

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