Documentation ¶
Index ¶
- Constants
- Variables
- func BuiltinEnvs(envs map[string]string)
- func Diff(srce *DataSource, dest []*DataSource, kind map[string]bool, ...) error
- func Exec(pref *Preference, dest []*DataSource, file []FileEntity, risk bool) error
- func ExitIfError(err error, code int, format string, args ...interface{})
- func ExitIfTrue(tru bool, code int, format string, args ...interface{})
- func LogDebug(m string, a ...interface{})
- func LogError(m string, a ...interface{})
- func LogFatal(m string, a ...interface{})
- func LogTrace(m string, a ...interface{})
- func MergeTmpl(tpl ShowTmpl, env map[string]interface{}, tbl string, con *MyConn) (string, error)
- func OutDebug(m string, a ...interface{})
- func OutTrace(m string, a ...interface{})
- func Revi(pref *Preference, dest []*DataSource, file []FileEntity, ...) error
- func ReviEach(pref *Preference, revs []ReviSeg, conn *MyConn, slt string, ...)
- func Show(srce *DataSource, ktpl []string, rgx []*regexp.Regexp) error
- func Sync(srce *DataSource, dest []*DataSource, kind map[string]bool, ...) error
- func Tree(pref *Preference, envs map[string]string, srce *DataSource, dest []*DataSource, ...) error
- func TreeRunSqlx(pref *Preference, sqlx *SqlExe, src *MyConn, dst []*MyConn, risk bool) error
- type Arg
- type Col
- type Config
- type Conn
- type CtrlJob
- type DataSource
- type DiffItem
- type Exe
- type FileEntity
- type GiftSeq
- type Hld
- type Idx
- type MyConn
- func (m *MyConn) Columns(table string) (map[string]Col, error)
- func (m *MyConn) DbConn() (db *sql.DB)
- func (m *MyConn) DbName() string
- func (m *MyConn) DdlTable(table string) (ddl string, err error)
- func (m *MyConn) DdlTrigger(trigger string) (ddl string, err error)
- func (m *MyConn) Exec(qr string, args ...interface{}) (int64, error)
- func (m *MyConn) Indexes(table string) (map[string]Idx, error)
- func (m *MyConn) Literal(val interface{}, col string) (string, bool)
- func (m *MyConn) Nothing(val interface{}) bool
- func (m *MyConn) Open(p *Preference, d *DataSource) (err error)
- func (m *MyConn) Query(fn func(*sql.Rows) error, qr string, args ...interface{}) error
- func (m *MyConn) Quotesc(str, qto string) string
- func (m *MyConn) TableNotFound(err error) bool
- func (m *MyConn) Tables() (tbs []string, err error)
- func (m *MyConn) Triggers(table string) (map[string]Trg, error)
- type Preference
- type ReviSeg
- type Room
- type ShowTmpl
- type Sql
- type SqlExe
- type Trg
Constants ¶
View Source
const ( CtrlExitcd = 99 CtrlRoomTree = "tree" )
View Source
const ( LvlDebug = 300 LvlTrace = 200 LvlError = 100 EnvSrcDb = "SRC-DB" EnvOutDb = "OUT-DB" EnvUser = "USER" EnvHost = "HOST" EnvDate = "DATE" EnvRule = "ENV-CHECK-RULE" EnvRuleEmpty = "EMPTY" SqlNull = "NULL" SqlTrue = "TRUE" SqlFalse = "FALSE" DiffSum = "sum" // 分别对比`-s`和多个`-d` 间的表名差异 DiffTrg = "trg" // 比较 trigger DiffTbl = "tbl" // 比较 column, index Joiner = "\n" SyncTbl = "tbl" // 同步表和索引 SyncTrg = "trg" // 同步trigger SyncRow = "row" // 同步数据 )
View Source
const ( ShowTblName = "${TABLE_NAME}" ShowTblDdl = "${TABLE_DDL}" ShowTgrName = "${TRIGGER_NAME}" ShowTgrDdl = "${TRIGGER_DDL}" ShowColBase = "${COLUMNS_BASE}" ShowColFull = "${COLUMNS_FULL}" )
View Source
const ( HoldTop = "ITSELF" CmndEnv = "ENV" CmndVar = "VAR" CmndRef = "REF" CmndStr = "STR" CmndSeq = "SEQ" CmndTbl = "TBL" CmndRun = "RUN" CmndOut = "OUT" ParaOne = "ONE" ParaFor = "FOR" ParaEnd = "END" ParaHas = "HAS" ParaNot = "NOT" )
Variables ¶
View Source
var ( MsgLevel = LvlDebug DiffType = map[string]bool{DiffSum: true, DiffTrg: true, DiffTbl: true} SyncType = map[string]bool{SyncTbl: true, SyncTrg: true, SyncRow: true} EmptyArr = make([]interface{}, 0) CtrlRoom = &Room{} )
View Source
var ShowParaRgx = regexp.MustCompile(`\$\{(TABLE_NAME|TABLE_DDL|TRIGGER_NAME|TRIGGER_DDL|COLUMNS_BASE|COLUMNS_FULL)\}`)
View Source
var SqlSplitRgx = regexp.MustCompile(`[\r\n]+`)
Functions ¶
func BuiltinEnvs ¶
func Diff ¶
func Diff(srce *DataSource, dest []*DataSource, kind map[string]bool, rgx []*regexp.Regexp) error
func Exec ¶
func Exec(pref *Preference, dest []*DataSource, file []FileEntity, risk bool) error
func ExitIfError ¶
func ExitIfTrue ¶
func Revi ¶
func Revi(pref *Preference, dest []*DataSource, file []FileEntity, revi, mask, rqry string, risk bool) error
func Sync ¶ added in v0.9.4
func Sync(srce *DataSource, dest []*DataSource, kind map[string]bool, rgx []*regexp.Regexp) error
func Tree ¶
func Tree(pref *Preference, envs map[string]string, srce *DataSource, dest []*DataSource, file []FileEntity, risk bool) error
func TreeRunSqlx ¶ added in v0.9.8
Types ¶
type Arg ¶
type Config ¶
type Config struct { Preference Preference SqlTemplet map[string]string DataSource map[string]DataSource StartupEnv map[string]string }
type Conn ¶
type Conn interface { // Open 打开链接 Open(p *Preference, d *DataSource) (err error) // DbConn 获得链接 DbConn() (db *sql.DB) // DbName 数据库名 DbName() string // Exec 执行脚本 Exec(qr string, args ...interface{}) (cnt int64, err error) // Query 执行查询 Query(fn func(*sql.Rows) error, qr string, args ...interface{}) (err error) // Tables 获得所有表名 Tables() (tbls []string, err error) // Columns 获得表的所有字段 Columns(table string) (cls map[string]Col, err error) // Indexes 获得表的所有索引 Indexes(table string) (ixs map[string]Idx, err error) // Triggers 获得表的所有触发器 Triggers(table string) (tgs map[string]Trg, err error) // DdlTable 生产建表SQL(含索引),格式化的 DdlTable(table string) (ddl string, err error) // DdlTrigger 生产建触发器SQL,格式化的 DdlTrigger(trigger string) (ddl string, err error) // Literal 转成SQL字面量,set x=val的 val部分字面量,是否需要引号扩上 // databaseTypeName sql.ColumnType.DatabaseTypeName Literal(val interface{}, databaseTypeName string) (string, bool) // Nothing 数值<=0|布尔false|NULL|字符串""|其他字面量为"" Nothing(val interface{}) bool // Quotesc 转义的字符串 Quotesc(str, qto string) string TableNotFound(err error) bool }
type DataSource ¶
type Exe ¶
type FileEntity ¶
func FileWalker ¶
func FileWalker(path []string, flag []string) ([]FileEntity, error)
type Hld ¶
type MyConn ¶
type MyConn struct { Pref *Preference Conn *sql.DB Name string }
func (*MyConn) Open ¶
func (m *MyConn) Open(p *Preference, d *DataSource) (err error)
func (*MyConn) Quotesc ¶
Quotesc https://github.com/mysql/mysql-server/blob/mysql-5.7.5/mysys/charset.c#L823-L932 https://github.com/mysql/mysql-server/blob/mysql-5.7.5/mysys/charset.c#L963-L1038
func (*MyConn) TableNotFound ¶ added in v0.9.8
type Preference ¶
type ShowTmpl ¶ added in v0.9.8
type Sql ¶
type Sql struct { Line string // 开始和结束行,全闭区间 Head int // 首行 Exeb bool // 语句,注释 File string // 文件名或名字 Text string // 正文部分 }
func ParseSqls ¶
func ParseSqls(pref *Preference, file *FileEntity) []Sql
type SqlExe ¶
func ParseTree ¶
func ParseTree(pref *Preference, envs map[string]string, file []FileEntity) ([]*SqlExe, error)
Click to show internal directories.
Click to hide internal directories.