Documentation ¶
Index ¶
- func RegistDirectiveFactory(factory func() Directive, tags ...string)
- type ColumnInfo
- type DBInfo
- type Directive
- type FKInfo
- type IndexInfo
- type NonterminalDirective
- type StmtInfo
- func (info *StmtInfo) Locals(key interface{}) interface{}
- func (info *StmtInfo) NumResultCol() int
- func (info *StmtInfo) ResultCols() []*datasrc.Column
- func (info *StmtInfo) SetLocals(key, val interface{})
- func (info *StmtInfo) StmtName() string
- func (info *StmtInfo) StmtType() string
- func (info *StmtInfo) String() string
- func (info *StmtInfo) Text() string
- func (info *StmtInfo) Valid() bool
- type TableInfo
- func (info *TableInfo) AutoIncColumn() *ColumnInfo
- 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) String() string
- 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) Col ¶
func (info *ColumnInfo) Col() *datasrc.TableColumn
Col returns the underly datasrc.TableColumn. 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) 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.
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>
A statement xml element contains SQL statement fragments and special directives.
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) NumResultCol ¶
NumResultCol returns the number of result columns. It returns 0 if info is nil or it is not "SELECT" statement.
func (*StmtInfo) ResultCols ¶
ResultCols returns result columns. It returns nil if info is nil.
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) 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.
NOTE: If the database does not support such sematic, it always returns nil.
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) FKByName ¶
FKByName returns the named foreign key. It returns nil if info is nil or not found.
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) // ProcessQueryResultColumns processes the result column information (in place) for SELECT query. // This method is called only when the query is a SELECT. ProcessQueryResultColumns(resultCols *[]*datasrc.Column) error // Fragment 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. Fragment() (string, error) }
TerminalDirective can not expand to other directives.