myctx

package
v0.0.0-...-3cb96c0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Committed

func Committed(ctx context.Context, f func(ctx context.Context))

Committed calls f after committed or immediate if not in tx

func Exec

func Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

Exec calls db.ExecContext

func IsInTx

func IsInTx(ctx context.Context) bool

IsInTx checks is context inside RunInTx

func Iter

func Iter(ctx context.Context, iter mysql.Iterator, query string, args ...interface{}) error

Iter calls mysql.IterContext

func Middleware

func Middleware(db DB) func(h http.Handler) http.Handler

Middleware injects db into request's context

func NewContext

func NewContext(ctx context.Context, db DB) context.Context

NewContext creates new context

func Prepare

func Prepare(ctx context.Context, query string) (*sql.Stmt, error)

Prepare calls db.PrepareContext

func Query

func Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

Query calls db.QueryContext

func QueryRow

func QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRow calls db.QueryRowContext

func RunInTx

func RunInTx(ctx context.Context, f func(ctx context.Context) error) error

RunInTx calls RunInTxOptions with default options

func RunInTxOptions

func RunInTxOptions(ctx context.Context, opt *mysql.TxOptions, f func(ctx context.Context) error) error

RunInTxOptions starts sql tx if not started

Types

type DB

type DB interface {
	Queryer
	mysql.BeginTxer
}

type Queryer

type Queryer interface {
	QueryRowContext(context.Context, string, ...interface{}) *sql.Row
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
	ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
	PrepareContext(context.Context, string) (*sql.Stmt, error)
}

Queryer interface

Jump to

Keyboard shortcuts

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