utils

package
v0.9.9 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2019 License: Apache-2.0 Imports: 18 Imported by: 23

Documentation

Index

Constants

View Source
const GLOB = "*"

The character which is treated like a glob

Variables

View Source
var (
	Version   = "None"
	BuildTS   = "None"
	GitHash   = "None"
	GitBranch = "None"
)

Version information.

View Source
var TxnTagSQLFormat = fmt.Sprintf("insert into `%s`.`%s`", dbNameV2, tableNameV2)

Only for test purpose

Functions

func CastSliceInterfaceToSliceString added in v0.9.8

func CastSliceInterfaceToSliceString(a []interface{}) ([]string, error)

func CastToSlice added in v0.9.8

func CastToSlice(arg interface{}) (out []interface{}, ok bool)

arg can be slice of any type

func CheckBinlogFormat

func CheckBinlogFormat(db *sql.DB) error

CheckBinlogFormat checks binlog format

func CloseDBConnection

func CloseDBConnection(db *sql.DB) error

func CloseDBConnections

func CloseDBConnections(dbs ...*sql.DB)

func CompareBinlogPos

func CompareBinlogPos(a, b gomysql.Position, deviation float64) int

CompareBinlogPos Compare binlog positions. The result will be 0 if |a-b| < deviation, otherwise -1 if a < b, and +1 if a > b.

func CreateDBConnection

func CreateDBConnection(cfg *DBConfig) (*sql.DB, error)

func CreateEtcdClient

func CreateEtcdClient(etcdEndpoints string) (*clientv3.Client, error)

func EstimateRowsCount

func EstimateRowsCount(db *sql.DB, schemaName string, tableName string) (int, error)

func GenHashKey

func GenHashKey(key string) uint32

GenHashKey generates key with crc32 algorithm

func GenerateRandomServerID

func GenerateRandomServerID() uint32

func GenerateTxnTagSQL added in v0.9.4

func GenerateTxnTagSQL(pipelineName string) string

func GetIndexRows

func GetIndexRows(db *sql.DB, statement string) ([][]sql.NullString, error)

func GetLabelEnvString

func GetLabelEnvString() string

func GetLabelsFromEnv

func GetLabelsFromEnv(envString string) (map[string]string, error)

func GetPrimaryKeys

func GetPrimaryKeys(db *sql.DB, schemaName string, tableName string) ([]string, error)

func GetScanPtrSafe

func GetScanPtrSafe(columnIdx int, columnTypes []*sql.ColumnType, vPtrs []interface{}) (interface{}, error)

func GetScanType

func GetScanType(columnType *sql.ColumnType) reflect.Type

GetScanType returns better scan type than go-sql-driver/mysql

func GetServerTimezone

func GetServerTimezone(db *sql.DB) (string, error)

GetServerTimezone get timezone of the MySQL server.

func GetTables

func GetTables(db *sql.DB) ([]string, error)

func GetUniqueIndexesWithoutPks

func GetUniqueIndexesWithoutPks(db *sql.DB, schemaName string, tableName string) ([]string, error)

func Glob

func Glob(pattern, subj string) bool

Glob will test a string pattern, potentially containing globs, against a subject string. The result is a simple true/false, determining whether or not the glob pattern matched the subject text.

func InitInternalTxnTags added in v0.9.4

func InitInternalTxnTags(db *sql.DB) error

func IsBinlogPurgedError

func IsBinlogPurgedError(err error) bool

func IsColumnString

func IsColumnString(columnType *sql.ColumnType) bool

func IsInternalTraffic added in v0.9.4

func IsInternalTraffic(db string, tbl string) bool

func LogRawInfo

func LogRawInfo(app string)

LogRotate prints the version information.

func MustCreateEtcdClient

func MustCreateEtcdClient(etcdEndpoints string) *clientv3.Client

func MustGetLabelsFromEnv

func MustGetLabelsFromEnv() map[string]string

func NewBinlogSyncer

func NewBinlogSyncer(serverID uint32, dbConfig *DBConfig) *replication.BinlogSyncer

func NewBoolPtr

func NewBoolPtr(b bool) *bool

func NewStringPtr

func NewStringPtr(s string) *string

func PrintRawInfo

func PrintRawInfo(app string)

PrintRawInfo prints the version information without log info.

func QueryGeneralRowsDataWithSQL

func QueryGeneralRowsDataWithSQL(db *sql.DB, statement string, args ...interface{}) ([][]interface{}, error)

func SQLWithAnnotation

func SQLWithAnnotation(annotation string, sql string) string

func ScanGeneralRows

func ScanGeneralRows(rows *sql.Rows, columnTypes []*sql.ColumnType) ([]interface{}, error)

func ScanGeneralRowsWithDataPtrs

func ScanGeneralRowsWithDataPtrs(rows *sql.Rows, columnTypes []*sql.ColumnType, vPtrs []interface{}) ([]interface{}, error)

func TableIdentity

func TableIdentity(schemaName string, tableName string) string

func TakeArg added in v0.9.8

func TakeArg(arg interface{}, kind reflect.Kind) (val reflect.Value, ok bool)

Types

type Closer

type Closer interface {
	Close()
}

type DBConfig

type DBConfig struct {
	Host                   string        `toml:"host" json:"host" mapstructure:"host"`
	Location               string        `toml:"location" json:"location" mapstructure:"location"`
	Username               string        `toml:"username" json:"username" mapstructure:"username"`
	Password               string        `toml:"password" json:"password" mapstructure:"password"`
	Port                   int           `toml:"port" json:"port" mapstructure:"port"`
	Schema                 string        `toml:"schema" json:"schema" mapstructure:"schema"`
	MaxIdle                int           `toml:"max-idle" json:"max-idle" mapstructure:"max-idle"`
	MaxOpen                int           `toml:"max-open" json:"max-open" mapstructure:"max-open"`
	MaxLifeTimeDurationStr string        `toml:"max-life-time-duration" json:"max-life-time-duration" mapstructure:"max-life-time-duration"`
	MaxLifeTimeDuration    time.Duration `toml:"-" json:"-" mapstructure:"-"`
}

DBConfig is the DB configuration.

func TestConfig

func TestConfig() *DBConfig

func (*DBConfig) ValidateAndSetDefault

func (dbc *DBConfig) ValidateAndSetDefault() error

type MySQLBinlogPosition

type MySQLBinlogPosition struct {
	BinLogFileName string `toml:"binlog-name" json:"binlog-name" max-life-time-duration:"binlog-name"`
	BinLogFilePos  uint32 `toml:"binlog-pos" json:"binlog-pos" max-life-time-duration:"binlog-pos"`
	BinlogGTID     string `toml:"binlog-gtid" json:"binlog-gtid" max-life-time-duration:"binlog-gtid"`
}

type MySQLDB

type MySQLDB struct {
	*sql.DB
}

func NewMySQLDB

func NewMySQLDB(db *sql.DB) MySQLDB

func (MySQLDB) GetMasterStatus

func (db MySQLDB) GetMasterStatus() (gomysql.Position, gomysql.MysqlGTIDSet, error)

func (MySQLDB) GetServerUUID

func (db MySQLDB) GetServerUUID() (string, error)

type MySQLStatusGetter

type MySQLStatusGetter interface {
	GetMasterStatus() (gomysql.Position, gomysql.MysqlGTIDSet, error)
	GetServerUUID() (string, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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