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: 0

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

func CheckMagic(rawSql string) (valid bool)

func CompareRemainStr

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

func CompareTime

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

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

func CompareWithStartTime

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

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

func CompareWithStartTimeInt

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

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

func CompareWithStartTimeStr

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

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

func Contains

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

func ConvertBool

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

func ConvertDate

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

func ConvertFloat

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

func ConvertLong

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

func ConvertMagicIndex

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

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

func ConvertString

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

func ConvertUUID

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

func EqualTime

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

查看时间是否相等

func GetInitScans

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

func GetOffsetIndex

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

func GetOffsetIndexWithTimeStamp

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

func GetRemainStr

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

func GetTimeFromArgs

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

func GetTimeFromData

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

func GetTimeIntFromArgs

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

func GetTimeIntFromData

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

func GetTimeStrFromData

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

func OpenSql

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

func QueryNumber

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

这个query只有一行

func RemoveWildcards

func RemoveWildcards(checkWildcards string, length int) int

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

func RestoreMeta

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

func RestoreSqls

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

func RestoreTimestampIntOffset

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

func RestoreTimestampOffset

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

func RestoreTimestampStrOffset

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

func SchemaCheck

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

func UpdateSqls

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

func WriteCacheMap

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

func WriteRecordsFile

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

WriteRecordsFile 将当前文件写入donefiel中

func WriteSqlsFile

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

WriteSqlsFile 将当前文件写入donefiel中

func WriteTimestampOffset

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

Types

type ByJson

type ByJson []jsonIndex

func (ByJson) Len

func (a ByJson) Len() int

func (ByJson) Less

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

func (ByJson) Swap

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

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

func (*DBRecords) SetTableRecords

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

type MagicRes

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

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

渲染魔法变量

type ReadInfo

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

func GetJson

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

GetJson return true, if bejson success

func SortByJson

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

if Marshal failed return all data

type SyncDBRecords

type SyncDBRecords struct {
	Records DBRecords
	Mutex   sync.RWMutex
}

func (*SyncDBRecords) CheckDoneRecords

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

func (*SyncDBRecords) GetDBRecords

func (syncDBRecords *SyncDBRecords) GetDBRecords() DBRecords

func (*SyncDBRecords) GetTableRecords

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

func (*SyncDBRecords) Reset

func (syncDBRecords *SyncDBRecords) Reset()

func (*SyncDBRecords) RestoreRecordsFile

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

func (*SyncDBRecords) SetTableInfo

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

func (*SyncDBRecords) SetTableRecords

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

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

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