mysql

package
v0.0.0-...-b81b3d3 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ExplainScalability = map[string]string{
	"NULL":            "NULL",
	"ALL":             "O(n)",
	"index":           "O(n)",
	"range":           "O(log n)+",
	"index_subquery":  "O(log n)+",
	"unique_subquery": "O(log n)+",
	"index_merge":     "O(log n)+",
	"ref_or_null":     "O(log n)+",
	"fulltext":        "O(log n)+",
	"ref":             "O(log n)",
	"eq_ref":          "O(log n)",
	"const":           "O(1)",
	"system":          "O(1)",
}

ExplainScalability ACCESS TYPE对应的运算复杂度 [AccessType]scalability map

Functions

func BuildSelectSQL

func BuildSelectSQL(table string, columns []string, conditions string) (string, error)

func NullFloat

func NullFloat(buf []byte) float64

NullFloat null able float

func NullInt

func NullInt(buf []byte) int64

NullInt null able int

func NullString

func NullString(buf []byte) string

NullString null able string

func TestMySQLConnect

func TestMySQLConnect(host, port, user, passwd, database string) error

Types

type Connect

type Connect struct {
	Addr     string
	User     string
	Pass     string
	Database string
	Charset  string
	Conn     *sql.DB
}

func NewMysqlConnect

func NewMysqlConnect(host, port, user, passwd, database string) (*Connect, error)

func (*Connect) Close

func (db *Connect) Close() error

func (*Connect) Explain

func (db *Connect) Explain(sql string) (exp *ExplainInfo, err error)

Explain 获取 SQL 的 explain 信息

func (*Connect) GetColumns

func (db *Connect) GetColumns(database, table string) ([]string, error)

GetColumns 查询表列

func (*Connect) Query

func (db *Connect) Query(sql string, params ...interface{}) (QueryResult, error)

Query 执行SQL

func (*Connect) ShowDatabases

func (db *Connect) ShowDatabases() ([]string, error)

ShowDatabases 查询库列表

func (*Connect) ShowTables

func (db *Connect) ShowTables(database string) ([]string, error)

ShowTables 查询表列表

func (*Connect) TableConstraints

func (db *Connect) TableConstraints(d, table string) (map[string][]string, error)

TableConstraints 查询表包含哪些约束

func (*Connect) TableSize

func (db *Connect) TableSize(database, table string) (int, error)

TableSize 查询表大小

func (*Connect) TablesHasPrimaryKey

func (db *Connect) TablesHasPrimaryKey(database string, tables []string) (bool, error)

TablesHasPrimaryKey 表是否有主键

type ExplainInfo

type ExplainInfo struct {
	SQL         string
	ExplainRows []ExplainRow
	Warnings    []ExplainWarning
}

ExplainInfo 用于存放Explain信息

type ExplainRow

type ExplainRow struct {
	ID           int
	SelectType   string
	TableName    string
	Partitions   string // explain partitions
	AccessType   string
	PossibleKeys []string
	Key          string
	KeyLen       string // 索引长度,如果发生了index_merge, KeyLen 格式为 N,N,所以不能定义为整型
	Ref          []string
	Rows         int64
	Filtered     float64 // 5.6 JSON, 5.7+, 5.5 EXTENDED
	Scalability  string  // O(1), O(n), O(log n), O(log n)+
	Extra        string
}

ExplainRow 单行Explain

type ExplainWarning

type ExplainWarning struct {
	Level   string
	Code    int
	Message string
}

ExplainWarning explain extended 后 SHOW WARNINGS 输出的结果

type QueryResult

type QueryResult struct {
	Rows    *sql.Rows
	Error   error
	Warning *sql.Rows
}

QueryResult 数据库查询返回值

Jump to

Keyboard shortcuts

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