sql

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: Apache-2.0 Imports: 21 Imported by: 6

Documentation

Index

Constants

View Source
const (
	SqlOffsetConnector   = "##"
	SqlSpliter           = ";"
	DefaultMySQLTable    = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA='DATABASE_NAME';"
	DefaultMySQLDatabase = "SHOW DATABASES;"
	DefaultPGSQLTable    = "SELECT TABLENAME FROM PG_TABLES WHERE SCHEMANAME='SCHEMA_NAME';"
	DefaultMSSQLTable    = "" /* 144-byte string literal not displayed */

	SupportReminder = "magic only support @(YYYY) @(YY) @(MM) @(DD) @(hh) @(mm) @(ss)"
	Wildcards       = "*"

	DefaultDoneRecordsFile = "sql.records"
	DefaultDoneSqlsFile    = "sqls"
	TimestampRecordsFile   = "timestamp.records"
	CacheMapFile           = "cachemap.records"
)
View Source
const (
	// 获取符合条件的table
	TABLE = iota
	// 获取符合条件的database
	DATABASE
	// 获取数据库表的总条数
	COUNT
)
View Source
const (
	// 获取数据条数的函数
	COUNTFUNC = iota
	// 获取读取数据的函数
	READFUNC
)
View Source
const (
	YEAR = iota
	MONTH
	DAY
	HOUR
	MINUTE
	SECOND
)

Variables

This section is empty.

Functions

func CheckMagic added in v1.5.4

func CheckMagic(rawSql string) (valid bool)

func CompareRemainStr added in v1.5.4

func CompareRemainStr(target, magicRemainStr, magicRet string, magicRemainIndex []int) bool

func CompareTime added in v1.5.4

func CompareTime(target, match string, timeStart, timeEnd []int, min bool) (valid bool)

查看时间是否符合, min为true则取出来为小于等于,min为false则取出来大于等于

func CompareWithStartTime added in v1.5.4

func CompareWithStartTime(data models.Data, timestampKey string, startTime time.Time) (int, bool)

-1 代表不存在; 1 代表更大; 0 代表相等

func CompareWithStartTimeInt added in v1.5.4

func CompareWithStartTimeInt(data models.Data, timestampKey string, startTimeInt int64) (int, bool)

-1 代表不存在; 1 代表更大; 0 代表相等

func CompareWithStartTimeStr added in v1.5.4

func CompareWithStartTimeStr(data models.Data, timestampKey, startTimeStr string) (int, bool)

-1 代表不存在; 1 代表更大; 0 代表相等

func Contains added in v1.5.4

func Contains(slice []string, str string) bool

func ConvertBool added in v1.5.4

func ConvertBool(v interface{}) (bool, error)

func ConvertDate added in v1.5.4

func ConvertDate(v interface{}) (time.Time, error)

func ConvertFloat added in v1.5.4

func ConvertFloat(v interface{}) (float64, error)

func ConvertLong added in v1.5.4

func ConvertLong(v interface{}) (int64, error)

func ConvertMagicIndex added in v1.5.4

func ConvertMagicIndex(magic string, now time.Time) (Ret string, index int)

仅支持 YYYY, YY, MM, DD, hh, mm, ss,不支持 M, D, h, m, s

func ConvertScanArgs added in v1.5.4

func ConvertScanArgs(data models.Data, scanArg interface{}, column, runnerName, name string,
	nochiced bool, schemas map[string]string) (int64, error)

func ConvertString added in v1.5.4

func ConvertString(v interface{}) (string, error)

func ConvertUUID added in v1.5.5

func ConvertUUID(v interface{}) (string, error)

func EqualTime added in v1.5.4

func EqualTime(target, magicRet string, timeStart, timeEnd []int) (valid bool)

查看时间是否相等

func GetInitScans added in v1.5.4

func GetInitScans(length int, rows *sql.Rows, schemas map[string]string, runnerName, name string) (scanArgs []interface{}, nochoiced []bool)

func GetOffsetIndex added in v1.5.4

func GetOffsetIndex(offsetKey string, columns []string) int

func GetOffsetIndexWithTimeStamp added in v1.5.4

func GetOffsetIndexWithTimeStamp(offsetKey, timestampKey string, columns []string) int

func GetRemainStr added in v1.5.4

func GetRemainStr(origin string, magicRemainIndex []int) (remainStr string)

func GetTimeFromArgs added in v1.5.4

func GetTimeFromArgs(offsetKeyIndex int, scanArgs []interface{}) (time.Time, bool)

func GetTimeFromData added in v1.5.4

func GetTimeFromData(data models.Data, timestampKey string) (time.Time, bool)

func GetTimeIntFromArgs added in v1.5.4

func GetTimeIntFromArgs(offsetKeyIndex int, scanArgs []interface{}) (int64, bool)

func GetTimeIntFromData added in v1.5.4

func GetTimeIntFromData(data models.Data, timestampKey string) (int64, bool)

func GetTimeStrFromData added in v1.5.4

func GetTimeStrFromData(data models.Data, timestampKey string) (string, bool)

func OpenSql added in v1.5.4

func OpenSql(dbtype, connectStr string) (db *sql.DB, err error)

func QueryNumber added in v1.5.4

func QueryNumber(tsql string, db *sql.DB) (int64, error)

这个query只有一行

func RemoveWildcards added in v1.5.4

func RemoveWildcards(checkWildcards string, length int) int

若包含通配符,字段长度相应 - 1

func RestoreMeta added in v1.5.4

func RestoreMeta(meta *reader.Meta, rawSqls string, magicLagDur time.Duration) (offsets []int64, sqls []string, omitMeta bool)

func RestoreSqls added in v1.5.4

func RestoreSqls(meta *reader.Meta) map[string]string

func RestoreTimestampIntOffset added in v1.5.4

func RestoreTimestampIntOffset(doneFilePath string) (int64, map[string]string, error)

func RestoreTimestampOffset added in v1.5.4

func RestoreTimestampOffset(doneFilePath string) (time.Time, map[string]string, error)

func RestoreTimestampStrOffset added in v1.5.4

func RestoreTimestampStrOffset(doneFilePath string) (string, map[string]string, error)

func SchemaCheck added in v1.5.4

func SchemaCheck(rawSchemas []string) (schemas map[string]string, err error)

func UpdateSqls added in v1.5.4

func UpdateSqls(rawsqls string, now time.Time) []string

func WriteCacheMap added in v1.5.4

func WriteCacheMap(doneFilePath string, cache map[string]string) (err error)

func WriteRecordsFile

func WriteRecordsFile(doneFilePath, content string) (err error)

WriteRecordsFile 将当前文件写入donefiel中

func WriteSqlsFile added in v1.5.4

func WriteSqlsFile(doneFilePath, content string) (err error)

WriteSqlsFile 将当前文件写入donefiel中

func WriteTimestampOffset added in v1.5.4

func WriteTimestampOffset(doneFilePath, content string) (err error)

Types

type ByJson added in v1.5.4

type ByJson []jsonIndex

func (ByJson) Len added in v1.5.4

func (a ByJson) Len() int

func (ByJson) Less added in v1.5.4

func (a ByJson) Less(i, j int) bool

func (ByJson) Swap added in v1.5.4

func (a ByJson) Swap(i, j int)

type DBRecords

type DBRecords map[string]TableRecords

func (*DBRecords) GetTableRecords

func (dbRecords *DBRecords) GetTableRecords(db string) TableRecords

func (*DBRecords) Reset

func (dbRecords *DBRecords) Reset()

func (*DBRecords) Set

func (dbRecords *DBRecords) Set(value DBRecords)

func (*DBRecords) SetTableInfo added in v1.5.2

func (dbRecords *DBRecords) SetTableInfo(db, table string, tableInfo TableInfo)

func (*DBRecords) SetTableRecords

func (dbRecords *DBRecords) SetTableRecords(db string, tableRecords TableRecords)

type MagicRes added in v1.5.3

type MagicRes struct {
	TimeStart   []int  // 按照 YY,MM,DD,hh,mm,ss 顺序记录时间位置
	TimeEnd     []int  // 按照 YY,MM,DD,hh,mm,ss 顺序记录时间长度
	RemainIndex []int  // 按顺序记录非时间字符串开始结束位置,去除 *
	Ret         string // 渲染结果,包含 *
}

func GoMagicIndex added in v1.5.4

func GoMagicIndex(rawSql string, now time.Time) (MagicRes, error)

渲染魔法变量

type ReadInfo added in v1.5.4

type ReadInfo struct {
	Data  models.Data
	Bytes int64
	Json  string //排序去重时使用,其他时候无用
}

func GetJson added in v1.5.4

func GetJson(datas []ReadInfo) ([]ReadInfo, bool)

GetJson return true, if bejson success

func SortByJson added in v1.5.4

func SortByJson(datas []ReadInfo) ([]ReadInfo, bool)

if Marshal failed return all data

type SyncDBRecords added in v1.5.1

type SyncDBRecords struct {
	Records DBRecords
	Mutex   sync.RWMutex
}

func (*SyncDBRecords) CheckDoneRecords added in v1.5.4

func (syncDBRecords *SyncDBRecords) CheckDoneRecords(target, curDB string) bool

func (*SyncDBRecords) GetDBRecords added in v1.5.1

func (syncDBRecords *SyncDBRecords) GetDBRecords() DBRecords

func (*SyncDBRecords) GetTableRecords added in v1.5.1

func (syncDBRecords *SyncDBRecords) GetTableRecords(db string) TableRecords

func (*SyncDBRecords) Reset added in v1.5.1

func (syncDBRecords *SyncDBRecords) Reset()

func (*SyncDBRecords) RestoreRecordsFile added in v1.5.4

func (dbRecords *SyncDBRecords) RestoreRecordsFile(meta *reader.Meta) (lastDB, lastTable string, omitDoneDBRecords bool)

func (*SyncDBRecords) SetTableInfo added in v1.5.2

func (syncDBRecords *SyncDBRecords) SetTableInfo(db, table string, tableInfo TableInfo)

func (*SyncDBRecords) SetTableRecords added in v1.5.1

func (syncDBRecords *SyncDBRecords) SetTableRecords(db string, tableRecords TableRecords)

type TableInfo

type TableInfo struct {
	Size   int64
	Offset int64
}

type TableRecords

type TableRecords struct {
	Table map[string]TableInfo
	Mutex sync.RWMutex
}

func (*TableRecords) GetTable added in v1.5.2

func (tableRecords *TableRecords) GetTable() map[string]TableInfo

func (*TableRecords) GetTableInfo

func (tableRecords *TableRecords) GetTableInfo(table string) TableInfo

func (*TableRecords) Reset

func (tableRecords *TableRecords) Reset()

func (*TableRecords) RestoreTableDone added in v1.5.4

func (tableRecords *TableRecords) RestoreTableDone(meta *reader.Meta, database string, tables []string) bool

func (*TableRecords) Set

func (tableRecords *TableRecords) Set(value TableRecords)

func (*TableRecords) SetTableInfo

func (tableRecords *TableRecords) SetTableInfo(table string, tableInfo TableInfo)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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