Documentation ¶
Index ¶
- func GetStructNames(bases []*QueryStructMeta) (names []string)
- func ParseStructRelationShip(relationship *schema.Relationships) []field.Relation
- type Clause
- type ElseClause
- type FieldParser
- type ForClause
- type ForRange
- type ITableInfo
- type IfClause
- type InterfaceMethod
- func (m *InterfaceMethod) DocComment() string
- func (m *InterfaceMethod) FuncSign() string
- func (m *InterfaceMethod) GetAssertInTmpl() string
- func (m *InterfaceMethod) GetParamInTmpl() string
- func (m *InterfaceMethod) GetResultParamInTmpl() string
- func (m *InterfaceMethod) GetTestParamInTmpl() string
- func (m *InterfaceMethod) GetTestResultParamInTmpl() string
- func (m *InterfaceMethod) GormRunMethodName() string
- func (m *InterfaceMethod) HasGotPoint() bool
- func (m *InterfaceMethod) HasNeedNewResult() bool
- func (m *InterfaceMethod) HasSQLData() bool
- func (m *InterfaceMethod) IsRepeatFromDifferentInterface(newMethod *InterfaceMethod) bool
- func (m *InterfaceMethod) IsRepeatFromSameInterface(newMethod *InterfaceMethod) bool
- func (m *InterfaceMethod) ReturnError() bool
- func (m *InterfaceMethod) ReturnNothing() bool
- func (m *InterfaceMethod) ReturnRowsAffected() bool
- func (m *InterfaceMethod) ReturnSQLResult() bool
- func (m *InterfaceMethod) ReturnSQLRow() bool
- func (m *InterfaceMethod) ReturnSQLRows() bool
- func (m *InterfaceMethod) SQLParamName(param string) string
- type QueryStructMeta
- func (b *QueryStructMeta) HasField() bool
- func (b QueryStructMeta) IfaceMode(on bool) *QueryStructMeta
- func (b *QueryStructMeta) QueryStructComment() string
- func (b *QueryStructMeta) Relations() (result []field.Relation)
- func (b *QueryStructMeta) ReturnObject() string
- func (b *QueryStructMeta) ReviseDIYMethod() error
- func (b *QueryStructMeta) ReviseFieldName()
- func (b *QueryStructMeta) ReviseFieldNameFor(keywords model.KeyWord)
- func (b *QueryStructMeta) StructComment() string
- type SQLClause
- type Section
- type SetClause
- type TrimClause
- type WhereClause
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetStructNames ¶
func GetStructNames(bases []*QueryStructMeta) (names []string)
GetStructNames get struct names from base structs
func ParseStructRelationShip ¶
func ParseStructRelationShip(relationship *schema.Relationships) []field.Relation
ParseStructRelationShip parse struct's relationship No one should use it directly in project
Types ¶
type Clause ¶
Clause a symbol of clause, it can be sql condition clause, if clause, where clause, set clause and else clause
type ElseClause ¶
type ElseClause struct {
IfClause
}
ElseClause else clause
func (ElseClause) String ¶
func (e ElseClause) String() (res string)
type FieldParser ¶
type ForClause ¶
type ForClause struct { Value []Clause ForRange ForRange // contains filtered or unexported fields }
ForClause set clause
type ForRange ¶
type ForRange struct {
// contains filtered or unexported fields
}
ForRange for range clause for diy method
type ITableInfo ¶
type ITableInfo interface { GetTableColumns(schemaName string, tableName string) (result []*model.Column, err error) GetTableIndex(schemaName string, tableName string) (indexes []gorm.Index, err error) }
ITableInfo table info interface
type IfClause ¶
type IfClause struct { Value []Clause // contains filtered or unexported fields }
IfClause if clause
type InterfaceMethod ¶
type InterfaceMethod struct { Doc string // comment S string // First letter of OriginStruct parser.Param // origin struct name TargetStruct string // generated query struct bane MethodName string // generated function name Params []parser.Param // function input params Result []parser.Param // function output params ResultData parser.Param // output data Section *Section // Parse split SQL into sections SQLParams []parser.Param // variable in sql need function input SQLString string // SQL GormOption string // gorm execute method Find or Exec or Take Table string // specified by user. if empty, generate it with gorm InterfaceName string // origin interface name Package string // interface package name HasForParams bool // }
InterfaceMethod interface's method
func BuildDIYMethod ¶
func BuildDIYMethod(f *parser.InterfaceSet, s *QueryStructMeta, data []*InterfaceMethod) (checkResults []*InterfaceMethod, err error)
BuildDIYMethod check the legitimacy of interfaces
func (*InterfaceMethod) DocComment ¶
func (m *InterfaceMethod) DocComment() string
DocComment return comment sql add "//" every line
func (*InterfaceMethod) FuncSign ¶
func (m *InterfaceMethod) FuncSign() string
FuncSign function signature
func (*InterfaceMethod) GetAssertInTmpl ¶
func (m *InterfaceMethod) GetAssertInTmpl() string
GetAssertInTmpl assert in diy test
func (*InterfaceMethod) GetParamInTmpl ¶
func (m *InterfaceMethod) GetParamInTmpl() string
GetParamInTmpl return param list
func (*InterfaceMethod) GetResultParamInTmpl ¶
func (m *InterfaceMethod) GetResultParamInTmpl() string
GetResultParamInTmpl return result list
func (*InterfaceMethod) GetTestParamInTmpl ¶
func (m *InterfaceMethod) GetTestParamInTmpl() string
GetTestParamInTmpl return param list
func (*InterfaceMethod) GetTestResultParamInTmpl ¶
func (m *InterfaceMethod) GetTestResultParamInTmpl() string
GetTestResultParamInTmpl return result list
func (*InterfaceMethod) GormRunMethodName ¶
func (m *InterfaceMethod) GormRunMethodName() string
GormRunMethodName return single data use Take() return array use Find
func (*InterfaceMethod) HasGotPoint ¶
func (m *InterfaceMethod) HasGotPoint() bool
HasGotPoint parameter has pointer or not
func (*InterfaceMethod) HasNeedNewResult ¶
func (m *InterfaceMethod) HasNeedNewResult() bool
HasNeedNewResult need pointer or not
func (*InterfaceMethod) HasSQLData ¶
func (m *InterfaceMethod) HasSQLData() bool
HasSQLData has variable or for params will creat params map
func (*InterfaceMethod) IsRepeatFromDifferentInterface ¶
func (m *InterfaceMethod) IsRepeatFromDifferentInterface(newMethod *InterfaceMethod) bool
IsRepeatFromDifferentInterface check different interface has same mame method
func (*InterfaceMethod) IsRepeatFromSameInterface ¶
func (m *InterfaceMethod) IsRepeatFromSameInterface(newMethod *InterfaceMethod) bool
IsRepeatFromSameInterface check different interface has same mame method
func (*InterfaceMethod) ReturnError ¶
func (m *InterfaceMethod) ReturnError() bool
ReturnError return error
func (*InterfaceMethod) ReturnNothing ¶
func (m *InterfaceMethod) ReturnNothing() bool
ReturnNothing not return error and rowAffected
func (*InterfaceMethod) ReturnRowsAffected ¶
func (m *InterfaceMethod) ReturnRowsAffected() bool
ReturnRowsAffected return rows affected
func (*InterfaceMethod) ReturnSQLResult ¶
func (m *InterfaceMethod) ReturnSQLResult() bool
ReturnSQLResult return sql result
func (*InterfaceMethod) ReturnSQLRow ¶
func (m *InterfaceMethod) ReturnSQLRow() bool
ReturnSQLRow return sql result
func (*InterfaceMethod) ReturnSQLRows ¶
func (m *InterfaceMethod) ReturnSQLRows() bool
ReturnSQLRows return sql result
func (*InterfaceMethod) SQLParamName ¶
func (m *InterfaceMethod) SQLParamName(param string) string
SQLParamName sql param map key,
type QueryStructMeta ¶
type QueryStructMeta struct { Generated bool // whether to generate db model FileName string // generated file name S string // the first letter(lower case)of simple Name (receiver) QueryStructName string // internal query struct name ModelStructName string // origin/model struct name TableName string // table name in db server TableComment string // table comment in db server StructInfo parser.Param Fields []*model.Field Source model.SourceCode ImportPkgPaths []string ModelMethods []*parser.Method // user custom method bind to db base struct // contains filtered or unexported fields }
QueryStructMeta struct info in generated code
func ConvertStructs ¶
func ConvertStructs(db *gorm.DB, structs ...interface{}) (metas []*QueryStructMeta, err error)
ConvertStructs convert to base structures
func GetQueryStructMeta ¶
GetQueryStructMeta generate db model by table name
func GetQueryStructMetaFromObject ¶
GetQueryStructMetaFromObject generate base struct from object
func (*QueryStructMeta) HasField ¶
func (b *QueryStructMeta) HasField() bool
HasField check if BaseStruct has fields
func (QueryStructMeta) IfaceMode ¶
func (b QueryStructMeta) IfaceMode(on bool) *QueryStructMeta
IfaceMode object mode
func (*QueryStructMeta) QueryStructComment ¶
func (b *QueryStructMeta) QueryStructComment() string
QueryStructComment query struct comment
func (*QueryStructMeta) Relations ¶
func (b *QueryStructMeta) Relations() (result []field.Relation)
Relations related field
func (*QueryStructMeta) ReturnObject ¶
func (b *QueryStructMeta) ReturnObject() string
ReturnObject return object in generated code
func (*QueryStructMeta) ReviseDIYMethod ¶
func (b *QueryStructMeta) ReviseDIYMethod() error
ReviseDIYMethod check diy method duplication name
func (*QueryStructMeta) ReviseFieldName ¶
func (b *QueryStructMeta) ReviseFieldName()
ReviseFieldName revise field name
func (*QueryStructMeta) ReviseFieldNameFor ¶
func (b *QueryStructMeta) ReviseFieldNameFor(keywords model.KeyWord)
ReviseFieldNameFor revise field name for keywords
func (*QueryStructMeta) StructComment ¶
func (b *QueryStructMeta) StructComment() string
StructComment struct comment
type SQLClause ¶
type SQLClause struct { Value []string // contains filtered or unexported fields }
SQLClause sql condition clause
type Section ¶
type Section struct { Tmpls []string ClauseTotal map[model.Status]int // contains filtered or unexported fields }
Section split sql into chunks
type SetClause ¶
type SetClause struct { Value []Clause // contains filtered or unexported fields }
SetClause set clause
type TrimClause ¶
type TrimClause struct { Value []Clause // contains filtered or unexported fields }
TrimClause set clause
func (TrimClause) String ¶
func (s TrimClause) String() string
type WhereClause ¶
type WhereClause struct { Value []Clause // contains filtered or unexported fields }
WhereClause where clause
func (WhereClause) String ¶
func (w WhereClause) String() string