mysql

package module
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: 8 Imported by: 0

README

mysql

Coverage Status Go Report Card GoDoc

mysql is the helper functions for MySQL/MariaDB

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAbortTx = errors.New("mysql: abort tx")

ErrAbortTx rollbacks transaction and return nil error

Functions

func Iter

func Iter(q interface {
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
}, iter Iterator, query string, args ...interface{}) error

func IterContext

func IterContext(ctx context.Context, q interface {
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
}, iter Iterator, query string, args ...interface{}) error

func JSON

func JSON(value interface{}) interface {
	driver.Valuer
	sql.Scanner
}

JSON wraps value with scanner and valuer

func NullString

func NullString(s *string) interface {
	driver.Valuer
	sql.Scanner
}

NullString scans null into empty string

func NullTime

func NullTime(t *time.Time) interface {
	driver.Valuer
	sql.Scanner
}

NullTime likes Time but wrap time.Time with scanner

func RunInTx

func RunInTx(db BeginTxer, opts *TxOptions, fn func(*sql.Tx) error) error

RunInTx runs fn inside retryable transaction.

see RunInTxContext for more info.

func RunInTxContext

func RunInTxContext(ctx context.Context, db BeginTxer, opts *TxOptions, fn func(*sql.Tx) error) error

RunInTxContext runs fn inside retryable transaction with context. It use Serializable isolation level if tx options isolation is setted to sql.LevelDefault.

RunInTxContext DO NOT handle panic. But when panic, it will rollback the transaction.

Types

type BeginTxer

type BeginTxer interface {
	BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error)
}

BeginTxer type

type Iterator

type Iterator func(scan Scanner) error

type QueryContext

type QueryContext interface {
	QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
}

QueryContext interface

type Scanner

type Scanner func(dest ...interface{}) error

type Time

type Time struct {
	time.Time
}

Time is the time.Time but can scan null into empty

func (*Time) Scan

func (t *Time) Scan(src interface{}) error

Scan implements Scanner interface

func (Time) Value

func (t Time) Value() (driver.Value, error)

Value implements Valuer interface

type TxOptions

type TxOptions struct {
	sql.TxOptions
	MaxAttempts int
}

TxOptions is the transaction options

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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