mysql

package
v0.0.78 Latest Latest
Warning

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

Go to latest
Published: May 7, 2022 License: MIT Imports: 20 Imported by: 2

Documentation

Index

Constants

View Source
const (
	DefaultMaxConns     = 100
	DefaultMaxIdleConns = 10
)

Default values for Mysql.

Variables

View Source
var File_pkg_database_mysql_mysql_proto protoreflect.FileDescriptor

Functions

func CloseDB added in v0.0.14

func CloseDB() error

func CloseTheDB added in v0.0.14

func CloseTheDB(conf DBConfig) error

func ConditionWithEqualAnd added in v0.0.55

func ConditionWithEqualAnd(condFields ...string) string

func ExecContext added in v0.0.34

func ExecContext(
	ctx context.Context,
	query string,
	arg interface{},
	tx *sqlx.Tx,
	db *sqlx.DB,
) (err error)

func GetCountContext added in v0.0.54

func GetCountContext(ctx context.Context, query string, arg interface{}, db *sqlx.DB) (count uint32, err error)

func GetDB added in v0.0.14

func GetDB() *sqlx.DB

func GetTheDB added in v0.0.14

func GetTheDB(conf DBConfig) (*sqlx.DB, error)

func InCondition added in v0.0.55

func InCondition(cond string, values ...string) string

func JoinNamedColumnsValues added in v0.0.33

func JoinNamedColumnsValues(cols ...string) string

JoinNamedColumnsValues foo=:foo,bar=:bar, for update set

func JoinNamedColumnsValuesWithOperator added in v0.0.33

func JoinNamedColumnsValuesWithOperator(cmp SqlCompare, oper SqlOperator, cols ...string) string

JoinNamedColumnsValuesWithOperator "foo=:foo AND bar=:bar" , for where condition

func NamedExecContext added in v0.0.54

func NamedExecContext(
	ctx context.Context,
	query string,
	arg interface{},
	tx *sqlx.Tx,
	db *sqlx.DB,
) (sql.Result, error)

func NamedInCondition added in v0.0.53

func NamedInCondition(oper SqlOperator, cols []string, arg interface{}) (string, error)

func NonzeroCondition added in v0.0.55

func NonzeroCondition(cmp SqlCompare, oper SqlOperator, arg interface{}) string

"foo=:foo AND bar=:bar"

func NonzeroFields added in v0.0.55

func NonzeroFields(arg interface{}) []string

func OrderCondition added in v0.0.55

func OrderCondition(orders map[string]bool) string

"ORDER BY create_time DESC, id DESC"

func PrepareNamedContext added in v0.0.54

func PrepareNamedContext(ctx context.Context,
	query string,
	tx *sqlx.Tx,
	db *sqlx.DB,
) (*sqlx.NamedStmt, error)

func SelectNamedContext added in v0.0.55

func SelectNamedContext(
	ctx context.Context,
	query string,
	arg interface{},
	dest interface{},
	db *sqlx.DB,
) (err error)

pointer struct model for dest

func TxPipelined added in v0.0.52

func TxPipelined(ctx context.Context, db *sqlx.DB, fn func(*sqlx.Tx) error) (err error)

Types

type CompletedConfig added in v0.0.32

type CompletedConfig struct {
	// contains filtered or unexported fields
}

func (CompletedConfig) New added in v0.0.32

func (c CompletedConfig) New(ctx context.Context) (*sqlx.DB, error)

type Config added in v0.0.32

type Config struct {
	Proto Mysql
	// contains filtered or unexported fields
}

func NewConfig added in v0.0.32

func NewConfig(options ...ConfigOption) *Config

func (*Config) ApplyOptions added in v0.0.32

func (o *Config) ApplyOptions(options ...ConfigOption) *Config

func (*Config) Complete added in v0.0.32

func (c *Config) Complete() CompletedConfig

Complete set default ServerRunOptions.

type ConfigOption added in v0.0.32

type ConfigOption interface {
	// contains filtered or unexported methods
}

A ConfigOption sets options.

func WithViper added in v0.0.32

func WithViper(v *viper.Viper) ConfigOption

type ConfigOptionFunc added in v0.0.32

type ConfigOptionFunc func(*Config)

ConfigOptionFunc wraps a function that modifies Client into an implementation of the ConfigOption interface.

type DB

type DB struct {
	//DSN        string
	Conf DBConfig
	// contains filtered or unexported fields
}

func NewDB

func NewDB(conf DBConfig, opts ...DBOption) *DB

func (*DB) ApplyOptions

func (o *DB) ApplyOptions(options ...DBOption) *DB

func (*DB) Close added in v0.0.14

func (d *DB) Close() error

func (*DB) GetDatabase

func (d *DB) GetDatabase() (*sqlx.DB, error)

func (*DB) GetDatabaseUntil

func (d *DB) GetDatabaseUntil(
	ctx context.Context,
	maxWaitInterval time.Duration,
	failAfter time.Duration,
) (*sqlx.DB, error)

type DBConfig

type DBConfig struct {
	Address  string
	DataName string
	UserName string
	Password string
}

type DBOption

type DBOption interface {
	// contains filtered or unexported methods
}

A DBOption sets options.

func WithConnMaxLifetime added in v0.0.32

func WithConnMaxLifetime(connMaxLifetime time.Duration) DBOption

func WithDialTimeout added in v0.0.32

func WithDialTimeout(dialTimeout time.Duration) DBOption

func WithInterpolateParams added in v0.0.59

func WithInterpolateParams(enabled bool) DBOption

func WithMaxConnections added in v0.0.32

func WithMaxConnections(maxConns int) DBOption

func WithMaxIdleConnections added in v0.0.32

func WithMaxIdleConnections(maxIdleConns int) DBOption

func WithReadTimeout added in v0.0.32

func WithReadTimeout(readTimeout time.Duration) DBOption

func WithWriteTimeout added in v0.0.32

func WithWriteTimeout(writeTimeout time.Duration) DBOption

type DBOptionFunc

type DBOptionFunc func(*DB)

DBOptionFunc wraps a function that modifies DB into an implementation of the DBOption interface.

type EmptyConfigOption added in v0.0.32

type EmptyConfigOption struct{}

EmptyConfigOption does not alter the configuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type EmptyDBOption

type EmptyDBOption struct{}

EmptyDBUrlOption does not alter the DBuration. It can be embedded in another structure to build custom options.

This API is EXPERIMENTAL.

type Mysql added in v0.0.32

type Mysql struct {
	Enabled            bool               `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"`
	Address            string             `protobuf:"bytes,2,opt,name=address,proto3" json:"address,omitempty"`
	Username           string             `protobuf:"bytes,3,opt,name=username,proto3" json:"username,omitempty"`
	Password           string             `protobuf:"bytes,4,opt,name=password,proto3" json:"password,omitempty"`
	DbName             string             `protobuf:"bytes,5,opt,name=db_name,json=dbName,proto3" json:"db_name,omitempty"`
	MaxConnections     int32              `protobuf:"varint,6,opt,name=max_connections,json=maxConnections,proto3" json:"max_connections,omitempty"`
	MaxIdleConnections int32              `protobuf:"varint,7,opt,name=max_idle_connections,json=maxIdleConnections,proto3" json:"max_idle_connections,omitempty"`
	DialTimeout        *duration.Duration `protobuf:"bytes,8,opt,name=dial_timeout,json=dialTimeout,proto3" json:"dial_timeout,omitempty"`
	ReadTimeout        *duration.Duration `protobuf:"bytes,9,opt,name=read_timeout,json=readTimeout,proto3" json:"read_timeout,omitempty"`
	// https://github.com/go-sql-driver/mysql#writetimeout
	WriteTimeout      *duration.Duration `protobuf:"bytes,10,opt,name=write_timeout,json=writeTimeout,proto3" json:"write_timeout,omitempty"`
	MaxLifeTime       *duration.Duration `protobuf:"bytes,11,opt,name=max_life_time,json=maxLifeTime,proto3" json:"max_life_time,omitempty"`
	MaxWaitDuration   *duration.Duration `protobuf:"bytes,12,opt,name=max_wait_duration,json=maxWaitDuration,proto3" json:"max_wait_duration,omitempty"`
	FailAfterDuration *duration.Duration `protobuf:"bytes,13,opt,name=fail_after_duration,json=failAfterDuration,proto3" json:"fail_after_duration,omitempty"`
	InterpolateParams bool               `protobuf:"varint,14,opt,name=interpolate_params,json=interpolateParams,proto3" json:"interpolate_params,omitempty"`
	// contains filtered or unexported fields
}

func (*Mysql) Descriptor deprecated added in v0.0.32

func (*Mysql) Descriptor() ([]byte, []int)

Deprecated: Use Mysql.ProtoReflect.Descriptor instead.

func (*Mysql) GetAddress added in v0.0.32

func (x *Mysql) GetAddress() string

func (*Mysql) GetDbName added in v0.0.32

func (x *Mysql) GetDbName() string

func (*Mysql) GetDialTimeout added in v0.0.32

func (x *Mysql) GetDialTimeout() *duration.Duration

func (*Mysql) GetEnabled added in v0.0.32

func (x *Mysql) GetEnabled() bool

func (*Mysql) GetFailAfterDuration added in v0.0.32

func (x *Mysql) GetFailAfterDuration() *duration.Duration

func (*Mysql) GetInterpolateParams added in v0.0.59

func (x *Mysql) GetInterpolateParams() bool

func (*Mysql) GetMaxConnections added in v0.0.32

func (x *Mysql) GetMaxConnections() int32

func (*Mysql) GetMaxIdleConnections added in v0.0.32

func (x *Mysql) GetMaxIdleConnections() int32

func (*Mysql) GetMaxLifeTime added in v0.0.32

func (x *Mysql) GetMaxLifeTime() *duration.Duration

func (*Mysql) GetMaxWaitDuration added in v0.0.32

func (x *Mysql) GetMaxWaitDuration() *duration.Duration

func (*Mysql) GetPassword added in v0.0.32

func (x *Mysql) GetPassword() string

func (*Mysql) GetReadTimeout added in v0.0.32

func (x *Mysql) GetReadTimeout() *duration.Duration

func (*Mysql) GetUsername added in v0.0.32

func (x *Mysql) GetUsername() string

func (*Mysql) GetWriteTimeout added in v0.0.32

func (x *Mysql) GetWriteTimeout() *duration.Duration

func (*Mysql) ProtoMessage added in v0.0.32

func (*Mysql) ProtoMessage()

func (*Mysql) ProtoReflect added in v0.0.32

func (x *Mysql) ProtoReflect() protoreflect.Message

func (*Mysql) Reset added in v0.0.32

func (x *Mysql) Reset()

func (*Mysql) String added in v0.0.32

func (x *Mysql) String() string

type SQLDB added in v0.0.14

type SQLDB atomic.Value

func (*SQLDB) Load added in v0.0.14

func (m *SQLDB) Load() *sqlx.DB

func (*SQLDB) Store added in v0.0.14

func (m *SQLDB) Store(value *sqlx.DB)

type SqlCompare added in v0.0.33

type SqlCompare string
const (
	SqlCompareEqual      SqlCompare = "="
	SqlCompareNotEqual   SqlCompare = "!="
	SqlCompareGreater    SqlCompare = ">"
	SqlCompareLessThan   SqlCompare = "<"
	SqlCompareGreatEqual SqlCompare = ">="
	SqlCompareLessEqual  SqlCompare = "<="
	SqlCompareLike       SqlCompare = "LIKE"
	SqlCompareIn         SqlCompare = "IN"
)

type SqlOperator added in v0.0.33

type SqlOperator string
const (
	SqlOperatorAnd SqlOperator = "AND"
	SqlOperatorOr  SqlOperator = "OR"
	SqlOperatorNot SqlOperator = "NOT"
)

type TxDao added in v0.0.42

type TxDao struct {
	*sqlx.Tx
}

func (*TxDao) Begin added in v0.0.42

func (d *TxDao) Begin(ctx context.Context, db *sqlx.DB, opts *sql.TxOptions) error

func (*TxDao) Commit added in v0.0.42

func (d *TxDao) Commit() error

func (*TxDao) Rollback added in v0.0.42

func (d *TxDao) Rollback() error

Rollback ...

Jump to

Keyboard shortcuts

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