mysql

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBreak = uerror.New(300, "break")

Functions

func New

func New() *mySQL

func Valid

func Valid() bool

Valid returns a bool valud to determine whether the connection is ready to use

Types

type NextFunc added in v0.0.17

type NextFunc func(*sql.Rows) error

NextFunc is designed for scanning all rows queryed from the database If error returned, it will cancel the loop in advance, and it will return the error. If ErrBreak returned, it will also cancel the loop in advance, but it will nil. If nil returned, it represents everything is OK.

type Option

type Option struct {
	Address  string `json:"address"`
	DBName   string `json:"dbname"`
	Username string `json:"username"`
	Password string `json:"password"`
	Port     int    `json:"port"`

	// MaxOpenConns sets the maximum number of open connections to the database
	MaxOpenConns int `json:"max_open_conns"`
	// MaxIdleConns sets the maximum number of connections in the idle connection pool.
	MaxIdleConns int `json:"max_idle_conns"`
}

type Proxy added in v0.0.17

type Proxy interface {
	// Transaction will start a transaction for the database
	// Ex.
	//		p.Transaction(ctx, func(tx *sql.Tx) error {
	//			tx.Exec(xxx)
	//			return nil // it will commit the transaction automatically
	//		})
	Transaction(ctx context.Context, fn TxFunc) error
	Query(ctx context.Context, query string, next NextFunc, args ...interface{}) error
	// QueryRow will query a row from the database
	// Ex.
	// 		var v1 string
	//		if err := p.QueryRow(ctx, []interface{}{&v1}, `SELECT xx FROM xx`, args); err != nil {
	//			// error
	//		}
	QueryRow(ctx context.Context, query string, dest []interface{}, args ...interface{}) error
	Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}

Proxy is a abstract layer for operating the MySQL database

func Client added in v0.0.6

func Client() Proxy

Client returns the handler to operate mysql if success

type TxFunc added in v0.0.17

type TxFunc func(tx *sql.Tx) error

TxFunc can be used for transaction operation If error returned, tx.Rollback() will be called automatically If nil returned, tx.Commit() will be called automatically, also.

Jump to

Keyboard shortcuts

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