Documentation ¶
Index ¶
- Constants
- Variables
- func BuildColumnsAndConstraints(colDefs []*ast.ColumnDef, constraints []*ast.Constraint) ([]*model.ColumnInfo, []*ast.Constraint)
- func BuildTableInfo(tableName model.CIStr, columns []*model.ColumnInfo, ...) (tbInfo *model.TableInfo, err error)
- func CloseDB(db *sql.DB) error
- func EqualTableInfo(tableInfo1, tableInfo2 *model.TableInfo) bool
- func FindColumnByName(cols []*model.ColumnInfo, name string) *model.ColumnInfo
- func FindSuitableIndex(ctx context.Context, db *sql.DB, schemaName string, tableInfo *model.TableInfo) (*model.ColumnInfo, error)
- func GetCRC32Checksum(ctx context.Context, db *sql.DB, schemaName, tableName string, ...) (int64, error)
- func GetCreateTableSQL(ctx context.Context, db *sql.DB, schemaName string, tableName string) (string, error)
- func GetDBVersion(ctx context.Context, db *sql.DB) (string, error)
- func GetRandomValues(ctx context.Context, db *sql.DB, schemaName, table, column string, num int64, ...) ([]interface{}, error)
- func GetRowCount(ctx context.Context, db *sql.DB, schemaName string, tableName string, ...) (int64, error)
- func GetSchemas(ctx context.Context, db *sql.DB) ([]string, error)
- func GetTableInfo(ctx context.Context, db *sql.DB, schemaName string, tableName string) (*model.TableInfo, error)
- func GetTableInfoBySQL(createTableSQL string) (table *model.TableInfo, err error)
- func GetTableInfoWithRowID(ctx context.Context, db *sql.DB, schemaName string, tableName string, ...) (*model.TableInfo, error)
- func GetTables(ctx context.Context, db *sql.DB, schemaName string) (tables []string, err error)
- func GetTidbLatestTSO(ctx context.Context, db *sql.DB) (int64, error)
- func IsFloatType(tp byte) bool
- func IsNumberType(tp byte) bool
- func IsTiDB(ctx context.Context, db *sql.DB) (bool, error)
- func OpenDB(cfg DBConfig) (*sql.DB, error)
- func ScanRow(rows *sql.Rows) (map[string][]byte, map[string]bool, error)
- func ScanRowsToInterfaces(rows *sql.Rows) ([][]interface{}, error)
- func SelectUniqueOrderKey(tbInfo *model.TableInfo) ([]string, []*model.ColumnInfo)
- func SetSnapshot(ctx context.Context, db *sql.DB, snapshot string) error
- func ShowBinlogFormat(ctx context.Context, db *sql.DB) (value string, err error)
- func ShowBinlogRowImage(ctx context.Context, db *sql.DB) (value string, err error)
- func ShowGrants(ctx context.Context, db *sql.DB, user, host string) ([]string, error)
- func ShowLogBin(ctx context.Context, db *sql.DB) (value string, err error)
- func ShowMySQLVariable(ctx context.Context, db *sql.DB, variable string) (value string, err error)
- func ShowServerID(ctx context.Context, db *sql.DB) (serverID uint64, err error)
- func ShowVersion(ctx context.Context, db *sql.DB) (value string, err error)
- func TableName(schema, table string) string
- type DBConfig
- type IndexInfo
Constants ¶
const ( // ImplicitColName is name of implicit column in TiDB ImplicitColName = "_tidb_rowid" // ImplicitColID is ID implicit column in TiDB ImplicitColID = -1 )
Variables ¶
var ( // ErrVersionNotFound means can't get the database's version ErrVersionNotFound = errors.New("can't get the database's version") )
Functions ¶
func BuildColumnsAndConstraints ¶
func BuildColumnsAndConstraints(colDefs []*ast.ColumnDef, constraints []*ast.Constraint) ([]*model.ColumnInfo, []*ast.Constraint)
BuildColumnsAndConstraints reference https://github.com/pingcap/tidb/blob/12c87929b8444571b9e84d2c0d5b85303d27da64/ddl/ddl_api.go#L168
func BuildTableInfo ¶
func BuildTableInfo(tableName model.CIStr, columns []*model.ColumnInfo, constraints []*ast.Constraint) (tbInfo *model.TableInfo, err error)
BuildTableInfo builds table infomation using column constraints.
func EqualTableInfo ¶
EqualTableInfo returns true if this two table info have same columns and indices
func FindColumnByName ¶
func FindColumnByName(cols []*model.ColumnInfo, name string) *model.ColumnInfo
FindColumnByName finds column by name.
func FindSuitableIndex ¶
func FindSuitableIndex(ctx context.Context, db *sql.DB, schemaName string, tableInfo *model.TableInfo) (*model.ColumnInfo, error)
FindSuitableIndex returns first column of a suitable index. The priority is * primary key * unique key * normal index which has max cardinality
func GetCRC32Checksum ¶
func GetCRC32Checksum(ctx context.Context, db *sql.DB, schemaName, tableName string, tbInfo *model.TableInfo, limitRange string, args []interface{}, ignoreColumns map[string]interface{}) (int64, error)
GetCRC32Checksum returns checksum code of some data by given condition
func GetCreateTableSQL ¶
func GetCreateTableSQL(ctx context.Context, db *sql.DB, schemaName string, tableName string) (string, error)
GetCreateTableSQL returns the create table statement.
func GetDBVersion ¶
GetDBVersion returns the database's version
func GetRandomValues ¶
func GetRandomValues(ctx context.Context, db *sql.DB, schemaName, table, column string, num int64, min, max interface{}, limitRange string, collation string) ([]interface{}, error)
GetRandomValues returns some random value of a column.
func GetRowCount ¶
func GetRowCount(ctx context.Context, db *sql.DB, schemaName string, tableName string, where string) (int64, error)
GetRowCount returns row count of the table. if not specify where condition, return total row count of the table.
func GetSchemas ¶
GetSchemas returns name of all schemas
func GetTableInfo ¶
func GetTableInfo(ctx context.Context, db *sql.DB, schemaName string, tableName string) (*model.TableInfo, error)
GetTableInfo returns table information.
func GetTableInfoBySQL ¶
GetTableInfoBySQL returns table information by given create table sql.
func GetTableInfoWithRowID ¶
func GetTableInfoWithRowID(ctx context.Context, db *sql.DB, schemaName string, tableName string, useRowID bool) (*model.TableInfo, error)
GetTableInfoWithRowID returns table information with _tidb_rowid column if useRowID is true
func GetTidbLatestTSO ¶
GetTidbLatestTSO returns tidb's current TSO.
func ScanRowsToInterfaces ¶
ScanRowsToInterfaces scans rows to interface arrary.
func SelectUniqueOrderKey ¶
func SelectUniqueOrderKey(tbInfo *model.TableInfo) ([]string, []*model.ColumnInfo)
SelectUniqueOrderKey returns some columns for order by condition.
func SetSnapshot ¶
SetSnapshot set the snapshot variable for tidb
func ShowBinlogFormat ¶
ShowBinlogFormat queries variable 'binlog_format' and returns its value.
func ShowBinlogRowImage ¶
ShowBinlogRowImage queries variable 'binlog_row_image' and returns its values.
func ShowGrants ¶
ShowGrants queries privileges for a mysql user.
func ShowLogBin ¶
ShowLogBin queries variable 'log_bin' and returns its value.
func ShowMySQLVariable ¶
ShowMySQLVariable queries MySQL variable and returns its value.
func ShowServerID ¶
ShowServerID queries variable 'server_id' and returns its value.
func ShowVersion ¶
ShowVersion queries variable 'version' and returns its value.
Types ¶
type DBConfig ¶
type DBConfig struct { Host string `toml:"host" json:"host"` Port int `toml:"port" json:"port"` User string `toml:"user" json:"user"` Password string `toml:"password" json:"password"` Schema string `toml:"schema" json:"schema"` }
DBConfig is database configuration.