Documentation
¶
Index ¶
- Constants
- Variables
- func NewParameter(column string, tp string, thirdPkg string) parameter.Parameter
- type Action
- type ByItem
- type ByItems
- func (b ByItems) IsValid() bool
- func (b ByItems) ParameterStructure(identifier string) (string, error)
- func (b ByItems) ParameterStructureName(identifier string) string
- func (b ByItems) ParameterThirdImports() (string, error)
- func (b ByItems) Parameters(pkg string) (string, error)
- func (b ByItems) SQL() (string, error)
- type Clause
- func (c *Clause) IsValid() bool
- func (c *Clause) ParameterStructure(identifier string) (string, error)
- func (c *Clause) ParameterStructureName(identifier string) string
- func (c *Clause) ParameterThirdImports() (string, error)
- func (c *Clause) Parameters(pkg string) (string, error)
- func (c *Clause) SQL() (string, error)
- type Column
- type ColumnOption
- type Columns
- type Comment
- type Constraint
- type Context
- type DDL
- type DML
- type DXL
- type DeleteStmt
- type Field
- type Fields
- type InsertStmt
- type Limit
- func (l *Limit) IsValid() bool
- func (l *Limit) LimitParameter(pkg string) string
- func (l *Limit) Multiple() bool
- func (l *Limit) OffsetParameter(pkg string) string
- func (l *Limit) One() bool
- func (l *Limit) ParameterStructure() (string, error)
- func (l *Limit) ParameterStructureName() string
- func (l *Limit) ParameterThirdImports() (string, error)
- func (l *Limit) Parameters(pkg string) (string, error)
- func (l *Limit) SQL() (string, error)
- type OP
- type SelectStmt
- type Table
- type Transaction
- type Type
- type UpdateStmt
Constants ¶
const ( ActionCreate // ActionCreate represents a create action. ActionRead // ActionRead represents a read action. ActionUpdate // ActionUpdate represents an update action. ActionDelete // ActionDelete represents a delete action. ActionTransaction // ActionTransaction represents a transaction action. )
const ( // TypeNullLongLong is a type extension for mysql.TypeLongLong. TypeNullLongLong byte = 0xf0 // TypeNullDecimal is a type extension for mysql.TypeDecimal. TypeNullDecimal byte = 0xf1 // TypeNullString is a type extension for mysql.TypeString. TypeNullString byte = 0xf2 )
const WildCard = "*"
WildCard is a wildcard column.
Variables ¶
Functions ¶
Types ¶
type ByItem ¶
type ByItem struct { // Column represents the column name. Column string // Desc returns true if order by Column desc. Desc bool // the below data are from table // ColumnInfo are the column info which are convert from Column. ColumnInfo Column // TableInfo is the table info. TableInfo *Table // the below data are from stmt // Comment represents a sql comment. Comment Comment }
ByItem represents an order-by or group-by item.
type ByItems ¶
type ByItems []*ByItem
ByItems returns the by items.
func (ByItems) ParameterStructure ¶
ParameterStructure returns the parameter type structure.
func (ByItems) ParameterStructureName ¶
ParameterStructureName returns the parameter structure name.
func (ByItems) ParameterThirdImports ¶
ParameterThirdImports returns the third package imports.
func (ByItems) Parameters ¶
Parameters returns the parameter variables.
type Clause ¶
type Clause struct { // Column represents the column name. Column string // Left represents the left expr. Left *Clause // Right represents the right expr. Right *Clause // OP represents the operator. OP OP // the below data are from table // ColumnInfo are the column info which are convert from Column. ColumnInfo Column // TableInfo is the table info. TableInfo *Table // the below data are from stmt // Comment represents a sql comment. Comment Comment }
Clause represents a where clause, having clause.
func (*Clause) ParameterStructure ¶
ParameterStructure returns the parameter type structure.
func (*Clause) ParameterStructureName ¶
ParameterStructureName returns the parameter structure name.
func (*Clause) ParameterThirdImports ¶
ParameterThirdImports returns the third package imports.
func (*Clause) Parameters ¶
Parameters returns the parameter variables.
type Column ¶
type Column struct { // ColumnOption is a column option. ColumnOption // Name is the name of the column. Name string // TP is the type of the column. TP byte AggregateCall bool }
Column represents a column in a table.
func (Column) HasComment ¶
type ColumnOption ¶
type ColumnOption struct { // AutoIncrement is true if the column allows auto increment. AutoIncrement bool // Comment is the comment of the column. Comment string // HasDefault is true if the column has default value. HasDefaultValue bool // TODO: Add default value // NotNull is true if the column is not null, false represents the column is null. NotNull bool // Unsigned is true if the column is unsigned. Unsigned bool }
ColumnOption is a column option.
type Comment ¶
type Comment struct { // OriginText represents the original sql text. OriginText string // LineText is the text of the line comment. LineText []string // FuncNames represents the generated function names. FuncName string }
Comment represents a sql comment.
type Constraint ¶
type Constraint struct { // Index is a list of column names that are part of an index, the key of map // // is the key name, the values are the column list. Index map[string][]string // PrimaryKey is a list of column names that are part of the primary key, the key of map // is the key name, the values are the column list. PrimaryKey map[string][]string // UniqueKey is a list of column names that are part of a unique ke, the key of map // // is the key name, the values are the column list. UniqueKey map[string][]string }
Constraint is a struct that contains the constraints of a table. ConstraintForeignKey,ConstraintFulltext,ConstraintCheck are ignored.
func (*Constraint) AppendIndex ¶
func (c *Constraint) AppendIndex(key string, columns ...string)
AppendIndex appends a column to the unique key.
func (*Constraint) AppendPrimaryKey ¶
func (c *Constraint) AppendPrimaryKey(key string, columns ...string)
AppendPrimaryKey appends a column to the primary key.
func (*Constraint) AppendUniqueKey ¶
func (c *Constraint) AppendUniqueKey(key string, columns ...string)
AppendUniqueKey appends a column to the unique key.
func (*Constraint) IsEmpty ¶
func (c *Constraint) IsEmpty() bool
IsEmpty returns true if the constraint is empty.
func (*Constraint) Merge ¶
func (c *Constraint) Merge(constraint *Constraint)
Merge merges the constraint with another constraint.
type Context ¶
type Context struct { Table *Table InsertStmt []*InsertStmt SelectStmt []*SelectStmt UpdateStmt []*UpdateStmt DeleteStmt []*DeleteStmt Transaction []*Transaction }
Context is sql table and query context.
type DDL ¶
type DDL struct { // Table represents a table in the database. Table *Table }
DDL represents a DDL statement.
type DML ¶
type DML interface { // SQLText returns the SQL text of the DML statement. SQLText() string // TableName returns the table of the DML statement. TableName() string // contains filtered or unexported methods }
DML represents a DML statement.
type DXL ¶
type DXL struct { // DDL represents a DDL statement. DDL []*DDL // DML represents a DML statement. DML []DML }
DXL describes ddl and dml.
type DeleteStmt ¶
type DeleteStmt struct { // Action represents the db action. Action Action // Comment represents a sql comment. Comment // From represents the operation table name, do not support multiple tables. From string // Limit represents the limit clause. Limit *Limit // OrderBy represents the order by clause. OrderBy ByItems // SQL represents the original sql text. SQL string // Where represents the where clause. Where *Clause // the below data are from table // FromInfo is the table info which is convert from From. FromInfo *Table }
DeleteStmt represents a delete statement.
func (*DeleteStmt) HasArg ¶
func (d *DeleteStmt) HasArg() bool
func (*DeleteStmt) SQLText ¶
func (d *DeleteStmt) SQLText() string
func (*DeleteStmt) TableName ¶
func (d *DeleteStmt) TableName() string
type InsertStmt ¶
type InsertStmt struct { // Action represents the db action. Action Action // Columns represents the operation columns. Columns []string // Comment represents a sql comment. Comment // SQL represents the original sql text. SQL string // Table represents the operation table name, do not support multiple tables. Table string // the below data are from table // ColumnInfo are the column info which are convert from Columns. ColumnInfo Columns // TableInfo is the table info which is convert from Table. TableInfo *Table }
InsertStmt represents a insert statement.
func (*InsertStmt) HasArg ¶
func (i *InsertStmt) HasArg() bool
func (*InsertStmt) SQLText ¶
func (i *InsertStmt) SQLText() string
func (*InsertStmt) TableName ¶
func (i *InsertStmt) TableName() string
type Limit ¶
type Limit struct { // Count represents the limit count. Count int64 // Offset represents the limit offset. Offset int64 // the below data are from table // TableInfo is the table info. TableInfo *Table // the below data are from stmt // Comment represents a sql comment. Comment Comment }
Limit represents a limit clause.
func (*Limit) LimitParameter ¶
LimitParameter returns the parameter variables.
func (*Limit) OffsetParameter ¶
OffsetParameter returns the parameter variables.
func (*Limit) ParameterStructure ¶
ParameterStructure returns the parameter type structure.
func (*Limit) ParameterStructureName ¶
ParameterStructureName returns the parameter structure name.
func (*Limit) ParameterThirdImports ¶
ParameterThirdImports returns the third package imports.
func (*Limit) Parameters ¶
Parameters returns the parameter variables.
type OP ¶
type OP int
OP is opcode type.
const ( ColumnValue OP And Between Case EQ Or GE GT In LE LT Like NE Not NotBetween NotIn NotLike Parentheses )
type SelectStmt ¶
type SelectStmt struct { // Action represents the db action. Action Action // SelectSQL represents the select filed sql. SelectSQL string // Columns represents the operation columns. Columns Fields // Comment represents a sql comment. Comment // Distinct represents the select distinct flag. Distinct bool // From represents the operation table name, do not support multiple tables. From string // GroupBy represents the group by clause. GroupBy ByItems // Having represents the having clause. Having *Clause // Limit represents the limit clause. Limit *Limit // OrderBy represents the order by clause. OrderBy ByItems // SQL represents the original sql text. SQL string // Where represents the where clause. Where *Clause // the below data are from table // ColumnInfo are the column info which are convert from Columns. ColumnInfo Columns // FromInfo is the table info which is convert from From. FromInfo *Table }
SelectStmt represents a select statement.
func (*SelectStmt) ContainsExtraColumns ¶
func (s *SelectStmt) ContainsExtraColumns() bool
ContainsExtraColumns returns true if the select statement contains extra columns.
func (*SelectStmt) HasArg ¶
func (s *SelectStmt) HasArg() bool
func (*SelectStmt) ReceiverName ¶
func (s *SelectStmt) ReceiverName() string
func (*SelectStmt) ReceiverStructure ¶
func (s *SelectStmt) ReceiverStructure(orm string) string
func (*SelectStmt) SQLText ¶
func (s *SelectStmt) SQLText() string
func (*SelectStmt) TableName ¶
func (s *SelectStmt) TableName() string
type Table ¶
type Table struct { // Columns is the list of columns in the table. Columns Columns // Constraint is a struct that contains the constraints of a table. // ConstraintForeignKey,ConstraintFulltext,ConstraintCheck are ignored. Constraint Constraint // Schema is the name of the schema that the table belongs to. Schema string // Name is the name of the table. Name string }
Table represents a table in the database.
func (*Table) ColumnList ¶
ColumnList is a list of column names.
func (*Table) GetColumnByName ¶
GetColumnByName returns the column with the given name.
func (*Table) HasOnePrimaryKey ¶
HasOnePrimaryKey returns true if the table has one primary key.
func (*Table) PrimaryColumn ¶
PrimaryColumn returns the primary column.
func (*Table) PrimaryColumnList ¶
PrimaryColumnList is a list of column names that are part of the primary key.
type Transaction ¶
type Transaction struct { // Action represents the db action. Action Action // Comment represents a sql comment. Comment // SQL represents the original sql text. SQL string // Statements represents the list of statement. Statements []DML // the below fields is convert from Statements Context }
func (Transaction) HasArg ¶
func (t Transaction) HasArg() bool
func (Transaction) SQLText ¶
func (t Transaction) SQLText() string
func (Transaction) TableName ¶
func (t Transaction) TableName() string
type UpdateStmt ¶
type UpdateStmt struct { // Action represents the db action. Action Action // Columns represents the operation columns. Columns []string // Comment represents a sql comment. Comment // Limit represents the limit clause. Limit *Limit // OrderBy represents the order by clause. OrderBy ByItems // SQL represents the original sql text. SQL string // Table represents the operation table name, do not support multiple tables. Table string // Where represents the where clause. Where *Clause // the below data are from table // ColumnInfo are the column info which are convert from Columns. ColumnInfo Columns // TableInfo is the table info which is convert from Table. TableInfo *Table }
UpdateStmt represents a update statement.
func (*UpdateStmt) HasArg ¶
func (u *UpdateStmt) HasArg() bool
func (*UpdateStmt) SQLText ¶
func (u *UpdateStmt) SQLText() string
func (*UpdateStmt) TableName ¶
func (u *UpdateStmt) TableName() string