executor

package
v0.0.0-...-f6814a1 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Example
package main

import (
	"fmt"

	_ "github.com/go-sql-driver/mysql"
)

var defaultMySQLDSNConfig = &Config{
	User:    "root",
	Host:    "localhost",
	Port:    3306,
	DB:      "test",
	Options: "charset=utf8mb4&collation=utf8mb4_bin",
}

var defaultTiDBDSNConfig = &Config{
	User:    "root",
	Host:    "127.0.0.1",
	Port:    4000,
	DB:      "test",
	Options: "charset=utf8mb4&collation=utf8mb4_bin",
}

func main() {
	exec := NewExecutor(defaultMySQLDSNConfig, defaultTiDBDSNConfig)
	if err := exec.Open(DefaultRetryCnt); err != nil {
		fmt.Printf("open failed err %v", err)
		return
	}

	sqls := []string{"drop table t", "create table t(a int)", "show create table t", "drop table t"}
	if err := exec.DoDiff(sqls, nil); err != nil {
		fmt.Printf("do diff failed \n%v", err)
	}
}
Output:

Index

Examples

Constants

View Source
const DefaultRetryCnt = 1

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string
	Port     int
	User     string
	Password string
	DB       string
	Options  string
}

func (*Config) Address

func (c *Config) Address() string

func (*Config) DSN

func (c *Config) DSN() string

type Executor

type Executor struct {
	MySQLConfig *Config
	TiDBConfig  *Config
	// contains filtered or unexported fields
}

func NewExecutor

func NewExecutor(mysql, tidb *Config) *Executor

func (*Executor) DoDiff

func (exec *Executor) DoDiff(sqls []string, handleResultsFn func(strs []string)) error

DoDiff executes sqls in the driver configured in exec. If there is an inconsistent sql execution result, it will directly return an error, and the error message contains inconsistencies. If the execution results are the same, no error is returned. handleResultsFn is used to do special processing on the results after executing each statement.

func (*Executor) Open

func (e *Executor) Open(retryCnt int) error

func (*Executor) Query

func (e *Executor) Query(query string) (*QueryResult, *QueryResult, error)

type QueryResult

type QueryResult struct {
	Result   *sql.Rows
	Error    error
	Rendered string
	// contains filtered or unexported fields
}

func (*QueryResult) Close

func (result *QueryResult) Close()

func (*QueryResult) Content

func (result *QueryResult) Content() string

func (*QueryResult) Stat

func (result *QueryResult) Stat() string

Jump to

Keyboard shortcuts

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