mysql

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 17 Imported by: 1

Documentation

Overview

nolint:lll

Index

Constants

View Source
const (
	QueryNoLimit  = 0
	QueryNoOffset = 0
)

Variables

View Source
var (
	ErrNoRows = errors.New("mysql: no rows")
	ErrTxDone = errors.New("mysql: tx done")

	// errors converted from MySQLError
	ErrDuplicateEntry = errors.New("mysql: duplicate entry")
)

Functions

func ConstructLimitOffsetSQLString

func ConstructLimitOffsetSQLString(limit, offset int) string

func ConstructOrderBySQLString

func ConstructOrderBySQLString(orders []*Order) string

func ConstructWhereSQLString

func ConstructWhereSQLString(wps []WherePart) (sql string, args []interface{})

Types

type Client

type Client interface {
	QueryExecer
	Close() error
	BeginTx(ctx context.Context) (Transaction, error)
	RunInTransaction(ctx context.Context, tx Transaction, f func() error) error
}

func NewClient

func NewClient(
	ctx context.Context,
	dbUser, dbPass, dbHost string,
	dbPort int,
	dbName string,
	opts ...Option,
) (Client, error)

type Execer

type Execer interface {
	ExecContext(ctx context.Context, query string, args ...interface{}) (Result, error)
}

type Filter

type Filter struct {
	Column   string
	Operator string
	Value    interface{}
}

func (*Filter) SQLString

func (f *Filter) SQLString() (sql string, args []interface{})

type InFilter

type InFilter struct {
	Column string
	Values []interface{}
}

func (*InFilter) SQLString

func (f *InFilter) SQLString() (sql string, args []interface{})

type JSONFilter

type JSONFilter struct {
	Column string
	Func   JSONFilterFunc
	Values []interface{}
}

func (*JSONFilter) SQLString

func (f *JSONFilter) SQLString() (sql string, args []interface{})

type JSONFilterFunc

type JSONFilterFunc int
const (
	JSONContainsNumber JSONFilterFunc
	JSONContainsString
	JSONLengthGreaterThan
	JSONLengthSmallerThan
	JSONContainsJSON
)

type JSONObject

type JSONObject struct {
	Val interface{}
}

func (*JSONObject) Scan

func (o *JSONObject) Scan(src interface{}) error

func (JSONObject) Value

func (o JSONObject) Value() (driver.Value, error)

type JSONPBObject

type JSONPBObject struct {
	Val proto.Message
}

func (*JSONPBObject) Scan

func (o *JSONPBObject) Scan(src interface{}) error

func (JSONPBObject) Value

func (o JSONPBObject) Value() (driver.Value, error)

type NullFilter

type NullFilter struct {
	Column string
	IsNull bool
}

func (*NullFilter) SQLString

func (f *NullFilter) SQLString() (sql string, args []interface{})

type Option

type Option func(*options)

func WithConnMaxIdleTime added in v0.3.0

func WithConnMaxIdleTime(it time.Duration) Option

func WithLogger

func WithLogger(logger *zap.Logger) Option

func WithMaxIdleConns

func WithMaxIdleConns(mic int) Option

func WithMaxOpenConns

func WithMaxOpenConns(moc int) Option

func WithMetrics

func WithMetrics(r metrics.Registerer) Option

type Order

type Order struct {
	Column    string
	Direction OrderDirection
}

func NewOrder

func NewOrder(column string, direction OrderDirection) *Order

type OrderDirection

type OrderDirection int
const (
	// default asc
	OrderDirectionAsc OrderDirection = iota
	OrderDirectionDesc
)

func (OrderDirection) String

func (o OrderDirection) String() string

type QueryExecer

type QueryExecer interface {
	Queryer
	Execer
}

type Queryer

type Queryer interface {
	QueryContext(ctx context.Context, query string, args ...interface{}) (Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) Row
}

type Result

type Result interface {
	LastInsertId() (int64, error)
	RowsAffected() (int64, error)
}

type Row

type Row interface {
	Err() error
	Scan(dest ...interface{}) error
}

type Rows

type Rows interface {
	Close() error
	Err() error
	Next() bool
	Scan(dest ...interface{}) error
}

type SearchQuery

type SearchQuery struct {
	Columns []string
	Keyword string
}

func (*SearchQuery) SQLString

func (q *SearchQuery) SQLString() (sql string, args []interface{})

type Transaction

type Transaction interface {
	QueryExecer
	Commit() error
	Rollback() error
}

type WherePart

type WherePart interface {
	SQLString() (sql string, args []interface{})
}

func NewFilter

func NewFilter(column, operator string, value interface{}) WherePart

func NewInFilter

func NewInFilter(column string, values []interface{}) WherePart

func NewJSONFilter

func NewJSONFilter(column string, f JSONFilterFunc, values []interface{}) WherePart

func NewNullFilter

func NewNullFilter(column string, isNull bool) WherePart

func NewSearchQuery

func NewSearchQuery(columns []string, keyword string) WherePart

Directories

Path Synopsis
Package mock is a generated GoMock package.
Package mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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