Documentation ¶
Index ¶
- Constants
- func GetStructNames(bases []*BaseStruct) (res []string)
- func ParseStructRelationShip(relationship *schema.Relationships) []field.Relation
- type BaseStruct
- type Clause
- type ElseClause
- type ForClause
- type ForRange
- type ITableInfo
- type IfClause
- type InterfaceMethod
- func (m *InterfaceMethod) DocComment() 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) ReturnRowsAffected() bool
- func (m *InterfaceMethod) SQLParamName(param string) string
- type SQLClause
- type Sections
- type SetClause
- type WhereClause
Constants ¶
const (
DefaultModelPkg = "model"
)
Variables ¶
This section is empty.
Functions ¶
func GetStructNames ¶
func GetStructNames(bases []*BaseStruct) (res []string)
func ParseStructRelationShip ¶
func ParseStructRelationShip(relationship *schema.Relationships) []field.Relation
ParseStructRelationShip parse struct's relationship No one should use it directly in project
Types ¶
type BaseStruct ¶
type BaseStruct struct { GenBaseStruct bool // whether to generate db model FileName string // generated file name S string // the first letter(lower case)of simple Name NewStructName string // new struct name StructName string // origin struct name TableName string // table name in db server StructInfo parser.Param Fields []*model.Field Source model.SourceCode ImportPkgPaths []string // contains filtered or unexported fields }
BaseStruct struct info in generated code
func CheckStructs ¶
func CheckStructs(db *gorm.DB, structs ...interface{}) (bases []*BaseStruct, err error)
CheckStructs check the legitimacy of structures
func GenBaseStructs ¶
GenBaseStructs generate db model by table name
func (*BaseStruct) HasField ¶
func (b *BaseStruct) HasField() bool
HasField check if BaseStruct has fields
func (*BaseStruct) Relations ¶
func (b *BaseStruct) Relations() (result []field.Relation)
func (*BaseStruct) ReviseFieldName ¶
func (b *BaseStruct) ReviseFieldName()
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) Creat ¶
func (e ElseClause) Creat() string
func (ElseClause) Finish ¶
func (e ElseClause) Finish() string
func (ElseClause) String ¶
func (e ElseClause) String() (res string)
type ForClause ¶
type ForClause struct { Value []Clause ForRange ForRange // contains filtered or unexported fields }
ForClause set clause
type ITableInfo ¶
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 Sections *Sections // 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 *BaseStruct, 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) 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
func (*InterfaceMethod) ReturnRowsAffected ¶
func (m *InterfaceMethod) ReturnRowsAffected() bool
func (*InterfaceMethod) SQLParamName ¶
func (m *InterfaceMethod) SQLParamName(param string) string
SQLParamName sql param map key,
type SQLClause ¶
type SQLClause struct { Value []string // contains filtered or unexported fields }
SQLClause sql condition clause
type Sections ¶
type Sections struct { Tmpl []string ClauseTotal map[model.Status]int // contains filtered or unexported fields }
Sections split sql into chunks
type SetClause ¶
type SetClause struct { Value []Clause // contains filtered or unexported fields }
SetClause set clause
type WhereClause ¶
type WhereClause struct { Value []Clause // contains filtered or unexported fields }
WhereClause where clause
func (WhereClause) Creat ¶
func (w WhereClause) Creat() string
func (WhereClause) Finish ¶
func (w WhereClause) Finish(name string) string
func (WhereClause) String ¶
func (w WhereClause) String() string