Documentation ¶
Index ¶
- Constants
- func WithExecutor(e *executor.Executor) contextOption
- type Context
- func (c *Context) AddSchema(name string)
- func (c *Context) AddSysVar(name, value string)
- func (c *Context) AddTable(schemaName, tableName string, table *TableInfo)
- func (c *Context) CurrentSchema() string
- func (c *Context) DelSchema(name string)
- func (c *Context) DelTable(schemaName, tableName string)
- func (c *Context) GetCollationDatabase(stmt *ast.TableName, schemaName string) (string, error)
- func (c *Context) GetColumnCardinality(tn *ast.TableName, columnName string) (int, error)
- func (c *Context) GetCreateTableStmt(stmt *ast.TableName) (*ast.CreateTableStmt, bool, error)
- func (c *Context) GetExecutionPlan(sql string) ([]*executor.ExplainRecord, error)
- func (c *Context) GetMaxIndexOptionForTable(stmt *ast.TableName, columnNames []string) (string, error)
- func (c *Context) GetSchema(schemaName string) (*SchemaInfo, bool)
- func (c *Context) GetSchemaCharacter(stmt *ast.TableName, schemaName string) (string, error)
- func (c *Context) GetSchemaEngine(stmt *ast.TableName, schemaName string) (string, error)
- func (c *Context) GetSchemaName(stmt *ast.TableName) string
- func (c *Context) GetSysVar(name string) (string, bool)
- func (c *Context) GetSystemVariable(name string) (string, error)
- func (c *Context) GetTable(schemaName, tableName string) (*TableInfo, bool)
- func (c *Context) GetTableInfo(stmt *ast.TableName) (*TableInfo, bool)
- func (c *Context) GetTableRowCount(tn *ast.TableName) (int, error)
- func (c *Context) GetTableSize(stmt *ast.TableName) (float64, error)
- func (c *Context) HasLoadSchemas() bool
- func (c *Context) HasLoadTables(schemaName string) (hasLoad bool)
- func (c *Context) HasSchema(schemaName string) (has bool)
- func (c *Context) HasTable(schemaName, tableName string) (has bool)
- func (c *Context) IsSchemaExist(schemaName string) (bool, error)
- func (c *Context) IsTableExist(stmt *ast.TableName) (bool, error)
- func (c *Context) IsTableExistInDatabase(tn *ast.TableName) (bool, error)
- func (c *Context) LoadSchemas(schemas []string)
- func (c *Context) LoadTables(schemaName string, tablesName []string)
- func (c *Context) Schemas() map[string]*SchemaInfo
- func (c *Context) SetCurrentSchema(schema string)
- func (c *Context) SetSchemasLoad()
- func (c *Context) UpdateContext(node ast.Node)
- type SchemaInfo
- type TableInfo
Constants ¶
const (
SysVarLowerCaseTableNames = "lower_case_table_names"
)
Variables ¶
This section is empty.
Functions ¶
func WithExecutor ¶
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context is a database information cache.
Is provides many methods to get database information.
It do lazy load and cache the information if executor provided. Otherwise, it only return from cache.
func NewContext ¶
NewContext creates a new context.
func NewMockContext ¶
NewMockContext creates a new mock context for unit test.
func (*Context) CurrentSchema ¶
CurrentSchema return current schema.
func (*Context) GetCollationDatabase ¶
GetCollationDatabase get collation database.
func (*Context) GetColumnCardinality ¶
func (*Context) GetCreateTableStmt ¶
GetCreateTableStmt get create table stmtNode for db by query; if table not exist, return null.
func (*Context) GetExecutionPlan ¶
func (c *Context) GetExecutionPlan(sql string) ([]*executor.ExplainRecord, error)
GetExecutionPlan get execution plan of SQL.
func (*Context) GetMaxIndexOptionForTable ¶
func (c *Context) GetMaxIndexOptionForTable(stmt *ast.TableName, columnNames []string) (string, error)
GetMaxIndexOptionForTable get max index option column of table.
func (*Context) GetSchemaCharacter ¶
GetSchemaCharacter get schema default character.
func (*Context) GetSchemaEngine ¶
GetSchemaEngine get schema default engine.
func (*Context) GetSchemaName ¶
GetSchemaName get schema name from AST or current schema.
func (*Context) GetSystemVariable ¶
GetSystemVariable get system variable.
func (*Context) GetTableInfo ¶
GetTableInfo get table info from context.
func (*Context) GetTableRowCount ¶
GetTableRowCount get table row count by show table status.
func (*Context) GetTableSize ¶
GetTableSize get table size.
func (*Context) HasLoadSchemas ¶
func (*Context) HasLoadTables ¶
func (*Context) IsSchemaExist ¶
IsSchemaExist check schema is exist or not.
func (*Context) IsTableExist ¶
IsTableExist check table is exist or not.
func (*Context) IsTableExistInDatabase ¶
IsTableExistInDatabase check table exist in database. Sometimes, we need explain on SQL, if table not exist, we will get error.
func (*Context) LoadSchemas ¶
func (*Context) LoadTables ¶
func (*Context) Schemas ¶
func (c *Context) Schemas() map[string]*SchemaInfo
Schemas return all schemas info in current context.
func (*Context) SetCurrentSchema ¶
func (*Context) SetSchemasLoad ¶
func (c *Context) SetSchemasLoad()
func (*Context) UpdateContext ¶
type SchemaInfo ¶
type TableInfo ¶
type TableInfo struct { Size float64 // OriginalTable save parser object from db by query "show create table ..."; // using in inspect and generate rollback sql OriginalTable *ast.CreateTableStmt // MergedTable *ast.CreateTableStmt // save alter table parse object from input sql; AlterTables []*ast.AlterTableStmt // contains filtered or unexported fields }