art

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SqlNull  = "NULL"
	SqlTrue  = "TRUE"
	SqlFalse = "FALSE"
)
View Source
const (
	TbName = "tbname" // 分别对比`-s`和多个`-d` 间的表名差异
	Detail = "detail" // 分别对比`-s`和多个`-d` 间的表明细(column, index,trigger)
	Create = "create" // 生成多库的创建DDL(table&index,trigger)
)
View Source
const (
	EnvUser      = "USER"
	EnvHost      = "HOST"
	EnvDate      = "DATE"
	EnvRule      = "ENV-CHECK-RULE"
	EnvRuleError = "ERROR"
	EnvRuleEmpty = "EMPTY"
)
View Source
const (
	//
	CmndEnv = "ENV"
	CmndRef = "REF"
	CmndStr = "STR"
	CmndRun = "RUN"
	CmndOut = "OUT"
	//
	ParaFor = "FOR"
	ParaOne = "ONE"
	ParaEnd = "END"
	ParaHas = "HAS"
	ParaNot = "NOT"
)
View Source
const (
	Joiner = "\n"
)

Variables

View Source
var DiffKinds = []string{TbName, Detail, Create}

Functions

func BuiltinEnvs

func BuiltinEnvs(envs map[string]string)

func Diff

func Diff(pref *Preference, srce *DataSource, dest []*DataSource, kind string, rgx []*regexp.Regexp) error

func Exec

func Exec(pref *Preference, dest []*DataSource, file []FileEntity, risk bool) error

func ExitIfError

func ExitIfError(err error, code int, format string, args ...interface{})

public

func ExitIfTrue

func ExitIfTrue(tru bool, code int, format string, args ...interface{})

func Revi

func Revi(pref *Preference, dest []*DataSource, file []FileEntity, revi, mask, rqry string, risk bool) error

func ReviEach

func ReviEach(pref *Preference, revs []ReviSeg, conn Conn, slt string, mask *regexp.Regexp, risk bool)

func RunExe

func RunExe(exe *Exe, src *MyConn, dst []*MyConn, ctx map[string]interface{}, outf func(exe *Exe, str string, src bool), risk bool) error

func RunSqlx

func RunSqlx(pref *Preference, sqlx *SqlExe, src *MyConn, dst []*MyConn, test bool) error

func Tree

func Tree(pref *Preference, envs map[string]string, srce *DataSource, dest []*DataSource, file []FileEntity, risk bool) error

Types

type Arg

type Arg struct {
	Line string // 开始和结束行,全闭区间
	Head int    // 首行
	Type string // 参数类型 Cmnd*
	Para string // 变量名
	Hold string // 占位符
}

type Col

type Col struct {
	Name string
	Seq  int
	Deft sql.NullString
	Null bool
	Type string
	Key  string
	Cmnt string
	Extr string
}

type Config

type Config struct {
	Preference Preference
	DataSource map[string]DataSource
	StartupEnv map[string]string
}

func ParseToml

func ParseToml(text string) (config *Config, err error)

type Conn

type Conn interface {
	// 打开链接
	Open(p *Preference, d *DataSource) (err error)
	// 获得链接
	DbConn() (db *sql.DB)
	// 数据库名
	DbName() string

	// 执行脚本
	Exec(qr string, args ...interface{}) (cnt int64, err error)
	// 执行查询
	Query(fn func(*sql.Rows) error, qr string, args ...interface{}) (err error)

	// 获得所有表名
	Tables() (tbls []string, err error)
	// 获得表的所有字段
	Columns(table string) (cls map[string]Col, err error)
	// 获得表的所有索引
	Indexes(table string) (ixs map[string]Idx, err error)
	// 获得表的所有触发器
	Triggers(table string) (tgs map[string]Trg, err error)

	// 生产建表SQL(含索引),包含结束符
	DdlTable(table string) (ddl string, err error)
	// 生产建触发器SQL,包含结束符
	DdlTrigger(trigger string) (ddl string, err error)

	// 转成SQL字面量,set x=val的 val部分字面量,是否需要引号扩上
	// databaseTypeName sql.ColumnType.DatabaseTypeName
	Literal(val interface{}, databaseTypeName string) (string, bool)
	// 数值<=0|布尔false|NULL|字符串""|其他字面量为""
	Nothing(val interface{}) bool
	// 转义的字符串
	Quotesc(str, qto string) string
}

type DataSource

type DataSource struct {
	Code string
	Conn string
}

type DiffItem

type DiffItem struct {
	Columns  map[string]Col
	Indexes  map[string]Idx
	Triggers map[string]Trg
}

type Exe

type Exe struct {
	Seg Sql // 对应的SQL片段

	// 产出
	Defs map[string]string // REF|STR的提取,key=HOLD,val=PARA
	// 行为
	Acts []*Arg // 源库RUN & OUT

	// 依赖,顺序重要
	Deps []*Hld // 依赖

	// 运行,深度优先L
	Sons []*Exe // 分叉
}

func (Exe) String

func (x Exe) String() string

type FileEntity

type FileEntity struct {
	Path string
	Text string
}

func FileWalker

func FileWalker(path []string, flag []string) ([]FileEntity, error)

type Hld

type Hld struct {
	Off int    // 开始位置,包含
	End int    // 结束位置,包括
	Ptn string // PARA的模式
	Str string // HOLD字符串
	Dyn bool   // true:动态替换;false:静态替换
}

type Idx

type Idx struct {
	Name string
	Uniq bool
	Cols string
	Type string
}

type MyConn

type MyConn struct {
	Pref *Preference
	Conn *sql.DB
	Name string
}

func (*MyConn) Columns

func (m *MyConn) Columns(table string) (map[string]Col, error)

func (*MyConn) DbConn

func (m *MyConn) DbConn() (db *sql.DB)

func (*MyConn) DbName

func (m *MyConn) DbName() string

func (*MyConn) DdlTable

func (m *MyConn) DdlTable(table string) (string, error)

func (*MyConn) DdlTrigger

func (m *MyConn) DdlTrigger(trigger string) (string, error)

func (*MyConn) Exec

func (m *MyConn) Exec(qr string, args ...interface{}) (int64, error)

func (*MyConn) Indexes

func (m *MyConn) Indexes(table string) (map[string]Idx, error)

func (*MyConn) Literal

func (m *MyConn) Literal(val interface{}, col string) (string, bool)

func (*MyConn) Nothing

func (m *MyConn) Nothing(val interface{}) bool

func (*MyConn) Open

func (m *MyConn) Open(p *Preference, d *DataSource) (err error)

func (*MyConn) Query

func (m *MyConn) Query(fn func(*sql.Rows) error, qr string, args ...interface{}) error

func (*MyConn) Tables

func (m *MyConn) Tables() ([]string, error)

func (*MyConn) Triggers

func (m *MyConn) Triggers(table string) (map[string]Trg, error)

type Preference

type Preference struct {
	DatabaseType string
	DelimiterRaw string
	DelimiterCmd string
	LineComment  string
	MultComment  []string
	FmtDateTime  string
	ConnMaxOpen  int
	ConnMaxIdel  int
}

type ReviSeg

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

type Sql

type Sql struct {
	Line string // 开始和结束行,全闭区间
	Head int    // 首行
	Exeb bool   // 语句,注释
	File string // 文件名或名字
	Text string // 正文部分
}

type SqlExe

type SqlExe struct {
	Envs map[string]string // HOLD对应的环境变量
	Exes []*Exe            // 数据树
}

func ParseSqlx

func ParseSqlx(sqls Sqls, envs map[string]string) (*SqlExe, error)

func ParseTree

func ParseTree(pref *Preference, envs map[string]string, file []FileEntity) ([]*SqlExe, error)

type Sqls

type Sqls []Sql

func ParseSqls

func ParseSqls(pref *Preference, file *FileEntity) Sqls

type Trg

type Trg struct {
	Name      string
	Timing    string
	Event     string
	Statement string
}

Jump to

Keyboard shortcuts

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