Documentation ¶
Index ¶
- func RegistDirectiveFactory(factory func() Directive, tags ...string)
- type ColumnInfo
- func (info *ColumnInfo) CamelName() string
- func (info *ColumnInfo) Col() *datasrc.ExtColumnType
- func (info *ColumnInfo) ColumnName() string
- func (info *ColumnInfo) DataType() string
- func (info *ColumnInfo) HasDefaultValue() bool
- func (info *ColumnInfo) Nullable() bool
- func (info *ColumnInfo) Pos() int
- func (info *ColumnInfo) Table() *TableInfo
- func (info *ColumnInfo) Valid() bool
- type DBInfo
- type Directive
- type FKInfo
- func (info *FKInfo) CamelName() string
- func (info *FKInfo) Columns() []*ColumnInfo
- func (info *FKInfo) FKName() string
- func (info *FKInfo) RefColumns() []*ColumnInfo
- func (info *FKInfo) RefTable() *TableInfo
- func (info *FKInfo) RefUniqueIndex() *IndexInfo
- func (info *FKInfo) Table() *TableInfo
- func (info *FKInfo) Valid() bool
- type IndexInfo
- type NonterminalDirective
- type StmtInfo
- func (info *StmtInfo) CamelName() string
- func (info *StmtInfo) Directives() []TerminalDirective
- func (info *StmtInfo) Locals(key interface{}) interface{}
- func (info *StmtInfo) NumQueryResultCol() int
- func (info *StmtInfo) Query() string
- func (info *StmtInfo) QueryResultCols() []*datasrc.ExtColumnType
- func (info *StmtInfo) SetLocals(key, val interface{})
- func (info *StmtInfo) StmtName() string
- func (info *StmtInfo) StmtSrc() string
- func (info *StmtInfo) StmtType() string
- func (info *StmtInfo) Text() string
- func (info *StmtInfo) Valid() bool
- type TableInfo
- func (info *TableInfo) AutoIncColumn() *ColumnInfo
- func (info *TableInfo) CamelName() string
- func (info *TableInfo) Column(i int) *ColumnInfo
- func (info *TableInfo) ColumnByName(columnName string) *ColumnInfo
- func (info *TableInfo) Columns() []*ColumnInfo
- func (info *TableInfo) FK(i int) *FKInfo
- func (info *TableInfo) FKByName(fkName string) *FKInfo
- func (info *TableInfo) FKs() []*FKInfo
- func (info *TableInfo) Index(i int) *IndexInfo
- func (info *TableInfo) IndexByName(indexName string) *IndexInfo
- func (info *TableInfo) Indices() []*IndexInfo
- func (info *TableInfo) NumColumn() int
- func (info *TableInfo) NumFK() int
- func (info *TableInfo) NumIndex() int
- func (info *TableInfo) Primary() *IndexInfo
- func (info *TableInfo) TableName() string
- func (info *TableInfo) Valid() bool
- type TerminalDirective
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegistDirectiveFactory ¶
RegistDirectiveFactory regist directive factories.
Types ¶
type ColumnInfo ¶
type ColumnInfo struct {
// contains filtered or unexported fields
}
ColumnInfo contains information of a table column.
func (*ColumnInfo) CamelName ¶
func (info *ColumnInfo) CamelName() string
CamelName is the camel case of the column name.
func (*ColumnInfo) Col ¶
func (info *ColumnInfo) Col() *datasrc.ExtColumnType
Col returns the underly datasrc.Column. It returns nil if info is nil.
func (*ColumnInfo) ColumnName ¶
func (info *ColumnInfo) ColumnName() string
ColumnName returns the table column name. It returns "" if info is nil.
func (*ColumnInfo) DataType ¶
func (info *ColumnInfo) DataType() string
DataType returns the data type of the table column. It returns "" if info is nil.
func (*ColumnInfo) HasDefaultValue ¶
func (info *ColumnInfo) HasDefaultValue() bool
HasDefaultValue returns true if the table column has default value (including 'AUTO_INCREMENT'/'NOW()'). It returns false if info is nil.
func (*ColumnInfo) Nullable ¶
func (info *ColumnInfo) Nullable() bool
Nullable returns the nullability of the table column. It returns true if info is nil.
func (*ColumnInfo) Pos ¶
func (info *ColumnInfo) Pos() int
Pos returns the position of the column in table. It returns -1 if info is nil.
func (*ColumnInfo) Table ¶
func (info *ColumnInfo) Table() *TableInfo
Table returns the tabe. It returns nil if info is nil.
type DBInfo ¶
type DBInfo struct {
// contains filtered or unexported fields
}
DBInfo contains information of a database.
func (*DBInfo) NumTable ¶
NumTable returns the number of table in the database. It returns 0 if info is nil.
func (*DBInfo) Table ¶
Table returns the i-th table in the database. It returns nil if info is nil or i is out of range.
func (*DBInfo) TableByName ¶
TableByName returns the named table in the database. It returns nil if info is nil or table not found.
type Directive ¶
type Directive interface { // Initialize the directive. Initialize(loader *datasrc.Loader, db *DBInfo, stmt *StmtInfo, tok etree.Token) error }
Directive represents a fragment of a statement.
type FKInfo ¶
type FKInfo struct {
// contains filtered or unexported fields
}
FKInfo contains information of a foreign key constraint.
func (*FKInfo) Columns ¶
func (info *FKInfo) Columns() []*ColumnInfo
Columns returns the composed columns. It returns nil if info is nil.
func (*FKInfo) RefColumns ¶
func (info *FKInfo) RefColumns() []*ColumnInfo
RefColumns returns the referenced columns. It returns nil if info is nil or ref table not found in current database.
func (*FKInfo) RefTable ¶
RefTable returns the referenced table. It returns nil if info is nil or ref table not found in current database.
func (*FKInfo) RefUniqueIndex ¶
RefUniqueIndex returns the referenced unique index. NOTE: It only returns unique index that have exactly the same group of columns as the referenced columns.
By SQL standard, the referenced columns should be a primary key or unique key of the referenced table to uniquely identify a row. But
InnoDB allows a foreign key constraint to reference a non-unique key. This is an InnoDB extension to standard SQL.
However
The handling of foreign key references to nonunique keys or keys that contain NULL values is not well defined (...) You are advised to use foreign keys that reference only UNIQUE (including PRIMARY) and NOT NULL keys.
type IndexInfo ¶
type IndexInfo struct {
// contains filtered or unexported fields
}
IndexInfo contains information of an index.
func (*IndexInfo) Columns ¶
func (info *IndexInfo) Columns() []*ColumnInfo
Columns returns the composed columns. It returns nil if info is nil.
func (*IndexInfo) IndexName ¶
IndexName returns the name of the index. It returns "" if info is nil.
type NonterminalDirective ¶
type NonterminalDirective interface { Directive // Expand to a list of xml tokens which will be converted to directives later. Expand() ([]etree.Token, error) }
NonterminalDirective can expand to other directives.
type StmtInfo ¶
type StmtInfo struct {
// contains filtered or unexported fields
}
StmtInfo contains information of a statement.
func NewStmtInfo ¶
NewStmtInfo creates a new StmtInfo from an xml element, example statement xml element:
<stmt name="BlogByUser"> <arg name="userId" type="int" /> SELECT <wc table="blog" /> FROM blog WHERE user_id=<repl with=":userId">1</repl> </stmt>
which contains SQL statement fragments and special directives.
func (*StmtInfo) Directives ¶
func (info *StmtInfo) Directives() []TerminalDirective
Directives returns the list of terminal directives the statement composed by.
func (*StmtInfo) Locals ¶
func (info *StmtInfo) Locals(key interface{}) interface{}
Locals returns the associated value for the given key in StmtInfo's locals map. This map is used by directives to store directive specific variables.
func (*StmtInfo) NumQueryResultCol ¶
NumQueryResultCol returns the number of result columns of the query if the statement is a SELECT.
func (*StmtInfo) Query ¶
Query returns the statement query. This is a valid SQL. It returns "" if info is nil.
func (*StmtInfo) QueryResultCols ¶
func (info *StmtInfo) QueryResultCols() []*datasrc.ExtColumnType
QueryResultCols returns the result columns of the query if the statement is a SELECT.
func (*StmtInfo) SetLocals ¶
func (info *StmtInfo) SetLocals(key, val interface{})
SetLocals set key/value into StmtInfo's locals map. See document in Locals.
func (*StmtInfo) StmtName ¶
StmtName returns the name of the StmtInfo. It returns "" if info is nil.
func (*StmtInfo) StmtSrc ¶
StmtSrc returns the source xml of this statement. It returns "" if info is nil.
func (*StmtInfo) StmtType ¶
StmtType returns the statement type, one of "SELECT"/"UPDATE"/"INSERT"/"UPDATE". It returns "" if info is nil.
type TableInfo ¶
type TableInfo struct {
// contains filtered or unexported fields
}
TableInfo contains information of a table.
func (*TableInfo) AutoIncColumn ¶
func (info *TableInfo) AutoIncColumn() *ColumnInfo
AutoIncColumn returns the single 'auto increment' column of the table. It returns nil if info is nil or auto increment column not exists.
func (*TableInfo) Column ¶
func (info *TableInfo) Column(i int) *ColumnInfo
Column returns the i-th column of the table. It returns nil if info is nil or i is out of range.
func (*TableInfo) ColumnByName ¶
func (info *TableInfo) ColumnByName(columnName string) *ColumnInfo
ColumnByName returns the named column. It returns nil if info is nil or not found.
func (*TableInfo) Columns ¶
func (info *TableInfo) Columns() []*ColumnInfo
Columns returns all columns in the table or nil if info is nil.
func (*TableInfo) FK ¶
FK returns the i-th foreign key in the table. It returns nil if info is nil or i is out of range.
func (*TableInfo) FKByName ¶
FKByName returns the named foreign key. It returns nil if info is nil or not found.
func (*TableInfo) Index ¶
Index returns the i-th index in the table. It returns nil if info is nil or i is out of range.
func (*TableInfo) IndexByName ¶
IndexByName return the named index in the table. It returns nil if info is nil or not found.
func (*TableInfo) Indices ¶
Indices returns all indices in the table. It returns nil if info is nil.
func (*TableInfo) NumColumn ¶
NumColumn returns the number of columns in the table or 0 if info is nil.
func (*TableInfo) NumFK ¶
NumFK returns the number of foreign key in the table. It returns 0 if info is nil.
func (*TableInfo) NumIndex ¶
NumIndex returns the number of indices in the table. It returns 0 if info is nil.
func (*TableInfo) Primary ¶
Primary returns the primary key of the table. It returns nil if info is nil or primary key not exists.
type TerminalDirective ¶
type TerminalDirective interface { Directive // QueryFragment returns the fragment of this directive to construct a valid SQL query. // The SQL query is used to determine statement type, to obtain result column information for SELECT query, // and optionally to check SQL correctness. QueryFragment() (string, error) // TextFragment returns the final fragment of this directive to construct a final statement text. // The statement text is no need to be a valid SQL query. It is up to the template to determine how to use it. TextFragment() (string, error) // ExtraProcess runs some extra process. ExtraProcess() error }
TerminalDirective can not expand to other directives.