mymy

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyTable  = errors.New("query builder: empty table")
	ErrEmptyValues = errors.New("query builder: empty values")
	ErrEmptyWhere  = errors.New("query builder: empty where clause")
)
View Source
var (
	ErrColumnNotFound = errors.New("column not found")
)

Functions

func RuleKey

func RuleKey(schema, table string) string

Types

type Action

type Action string
const (
	ActionInsert Action = "insert"
	ActionUpdate Action = "update"
	ActionDelete Action = "delete"
)

type BaseEventHandler

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

BaseEventHandler is a default implementation of the EventHandler. Use it as base for your custom handlers in the plugins.

func NewBaseEventHandler

func NewBaseEventHandler(table string) *BaseEventHandler

func (*BaseEventHandler) OnRows

func (eH *BaseEventHandler) OnRows(e *RowsEvent) ([]*Query, error)

func (*BaseEventHandler) OnTableChanged added in v1.1.0

func (eH *BaseEventHandler) OnTableChanged(_ SourceInfo) error

func (*BaseEventHandler) Skip

func (eH *BaseEventHandler) Skip(cols []string)

Skip sets list of columns which should be skipped during the replication.

This option is mutually exclusive with SyncOnly.

func (*BaseEventHandler) SyncOnly

func (eH *BaseEventHandler) SyncOnly(cols []string)

SyncOnly sets list of columns which should be replicated.

This option is mutually exclusive with Skip.

type Column

type Column struct {
	Index      uint64
	Name       string
	Type       ColumnType
	Collation  string
	IsAuto     bool
	IsUnsigned bool
	IsVirtual  bool
}

func (*Column) GetValue

func (c *Column) GetValue(row []interface{}) (interface{}, error)

type ColumnType

type ColumnType int
const (
	TypeNumber    ColumnType = iota + 1 // tinyint, smallint, int, bigint, year
	TypeFloat                           // float, double
	TypeEnum                            // enum
	TypeSet                             // set
	TypeString                          // char, varchar, etc.
	TypeDatetime                        // datetime
	TypeTimestamp                       // timestamp
	TypeDate                            // date
	TypeTime                            // time
	TypeBit                             // bit
	TypeJSON                            // json
	TypeDecimal                         // decimal
	TypeMediumInt                       // medium int
	TypeBinary                          // binary, varbinary
	TypePoint                           // coordinates
)

type EventHandler

type EventHandler interface {
	OnTableChanged(info SourceInfo) error
	OnRows(e *RowsEvent) ([]*Query, error)
}

EventHandler handles incoming events from the master.

type Query

type Query struct {
	Action Action
	Table  string
	Values []QueryArg
	Where  []QueryArg
}

func (*Query) SQL

func (q *Query) SQL() (sql string, args []interface{}, err error)

type QueryArg

type QueryArg struct {
	Field string
	Value interface{}
}

type RowsEvent

type RowsEvent struct {
	Action Action
	Source SourceInfo
	// Rows is a changed row list.
	//
	// Update events has even rows number.
	// Two rows for one update event: [before update row, after update row].
	Rows [][]interface{}
}

type Rule

type Rule struct {
	Source  SourceInfo
	Handler EventHandler
}

type SourceInfo

type SourceInfo struct {
	Schema string
	Table  string
	PKs    []Column
	Cols   []Column
}

func (SourceInfo) FindColumnByName added in v1.1.0

func (info SourceInfo) FindColumnByName(name string) (Column, error)

Jump to

Keyboard shortcuts

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