infos

package
v0.7.10 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegistDirectiveFactory

func RegistDirectiveFactory(factory func() Directive, tags ...string)

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.

func (*ColumnInfo) Valid

func (info *ColumnInfo) Valid() bool

Valid returns true if info != nil.

type DBInfo

type DBInfo struct {
	// contains filtered or unexported fields
}

DBInfo contains information of a database.

func NewDBInfo

func NewDBInfo(loader *datasrc.Loader) (*DBInfo, error)

NewDBInfo extracts information from current database.

func (*DBInfo) NumTable

func (info *DBInfo) NumTable() int

NumTable returns the number of table in the database. It returns 0 if info is nil.

func (*DBInfo) Table

func (info *DBInfo) Table(i int) *TableInfo

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

func (info *DBInfo) TableByName(tableName string) *TableInfo

TableByName returns the named table in the database. It returns nil if info is nil or table not found.

func (*DBInfo) Tables

func (info *DBInfo) Tables() []*TableInfo

Tables returns all tables in the database. It returns nil if info is nil.

func (*DBInfo) Valid

func (info *DBInfo) Valid() bool

Valid returns true if info != nil.

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) CamelName

func (info *FKInfo) CamelName() string

CamelName is camel case of the fk name.

func (*FKInfo) Columns

func (info *FKInfo) Columns() []*ColumnInfo

Columns returns the composed columns. It returns nil if info is nil.

func (*FKInfo) FKName

func (info *FKInfo) FKName() string

FKName returns the name of foreign key. It returns "" 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

func (info *FKInfo) RefTable() *TableInfo

RefTable returns the referenced table. It returns nil if info is nil or ref table not found in current database.

func (*FKInfo) RefUniqueIndex

func (info *FKInfo) RefUniqueIndex() *IndexInfo

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.

func (*FKInfo) Table

func (info *FKInfo) Table() *TableInfo

Table returns the table. It returns nil if info is nil.

func (*FKInfo) Valid

func (info *FKInfo) Valid() bool

Valid returns true if info != nil.

type IndexInfo

type IndexInfo struct {
	// contains filtered or unexported fields
}

IndexInfo contains information of an index.

func (*IndexInfo) CamelName

func (info *IndexInfo) CamelName() string

CamelName is camel case of the index name.

func (*IndexInfo) Columns

func (info *IndexInfo) Columns() []*ColumnInfo

Columns returns the composed columns. It returns nil if info is nil.

func (*IndexInfo) IndexName

func (info *IndexInfo) IndexName() string

IndexName returns the name of the index. It returns "" if info is nil.

func (*IndexInfo) IsPrimary

func (info *IndexInfo) IsPrimary() bool

IsPrimary returns true if this is a valid primary index.

func (*IndexInfo) IsUnique

func (info *IndexInfo) IsUnique() bool

IsUnique returns true if this is a valid unique index.

func (*IndexInfo) Table

func (info *IndexInfo) Table() *TableInfo

Table returns the table. It returns nil if info is nil.

func (*IndexInfo) Valid

func (info *IndexInfo) Valid() bool

Valid returns true if info != 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

func NewStmtInfo(loader *datasrc.Loader, db *DBInfo, stmtElem *etree.Element) (*StmtInfo, error)

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) CamelName

func (info *StmtInfo) CamelName() string

CamelName is the camel case of stmt name.

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

func (info *StmtInfo) NumQueryResultCol() int

NumQueryResultCol returns the number of result columns of the query if the statement is a SELECT.

func (*StmtInfo) Query

func (info *StmtInfo) Query() string

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

func (info *StmtInfo) StmtName() string

StmtName returns the name of the StmtInfo. It returns "" if info is nil.

func (*StmtInfo) StmtSrc

func (info *StmtInfo) StmtSrc() string

StmtSrc returns the source xml of this statement. It returns "" if info is nil.

func (*StmtInfo) StmtType

func (info *StmtInfo) StmtType() string

StmtType returns the statement type, one of "SELECT"/"UPDATE"/"INSERT"/"UPDATE". It returns "" if info is nil.

func (*StmtInfo) Text

func (info *StmtInfo) Text() string

Text returns the statement text. It returns "" if info is nil.

func (*StmtInfo) Valid

func (info *StmtInfo) Valid() bool

Valid returns true if info != 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) CamelName

func (info *TableInfo) CamelName() string

CamelName is the camel case of the table name.

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

func (info *TableInfo) FK(i int) *FKInfo

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

func (info *TableInfo) FKByName(fkName string) *FKInfo

FKByName returns the named foreign key. It returns nil if info is nil or not found.

func (*TableInfo) FKs

func (info *TableInfo) FKs() []*FKInfo

FKs returns all foreign keys in the table. It returns nil if info is nil.

func (*TableInfo) Index

func (info *TableInfo) Index(i int) *IndexInfo

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

func (info *TableInfo) IndexByName(indexName string) *IndexInfo

IndexByName return the named index in the table. It returns nil if info is nil or not found.

func (*TableInfo) Indices

func (info *TableInfo) Indices() []*IndexInfo

Indices returns all indices in the table. It returns nil if info is nil.

func (*TableInfo) NumColumn

func (info *TableInfo) NumColumn() int

NumColumn returns the number of columns in the table or 0 if info is nil.

func (*TableInfo) NumFK

func (info *TableInfo) NumFK() int

NumFK returns the number of foreign key in the table. It returns 0 if info is nil.

func (*TableInfo) NumIndex

func (info *TableInfo) NumIndex() int

NumIndex returns the number of indices in the table. It returns 0 if info is nil.

func (*TableInfo) Primary

func (info *TableInfo) Primary() *IndexInfo

Primary returns the primary key of the table. It returns nil if info is nil or primary key not exists.

func (*TableInfo) TableName

func (info *TableInfo) TableName() string

TableName returns the table name or "" if info is nil.

func (*TableInfo) Valid

func (info *TableInfo) Valid() bool

Valid returns true if info != nil.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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