check

package
v0.2.31 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
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
	// 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

func GenBaseStructs(db *gorm.DB, conf model.Conf) (bases *BaseStruct, err error)

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

type Clause interface {
	String() string
	Creat() string
}

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

func (ForClause) Creat

func (f ForClause) Creat() string

func (ForClause) Finish

func (f ForClause) Finish() string

func (ForClause) String

func (f ForClause) String() string

type ForRange

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

func (*ForRange) DataValue

func (f *ForRange) DataValue(dataName, clauseName string) string

func (*ForRange) String

func (f *ForRange) String() string

type ITableInfo

type ITableInfo interface {
	GetTbColumns(schemaName string, tableName string) (result []*model.Column, err error)

	GetTbIndex(schemaName string, tableName string) (result []*model.Index, err error)
}

type IfClause

type IfClause struct {
	Value []Clause
	// contains filtered or unexported fields
}

IfClause if clause

func (IfClause) Creat

func (i IfClause) Creat() string

func (IfClause) Finish

func (i IfClause) Finish() string

func (IfClause) String

func (i IfClause) String() string

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

func (SQLClause) Creat

func (s SQLClause) Creat() string

func (SQLClause) Finish

func (s SQLClause) Finish() string

func (SQLClause) String

func (s SQLClause) String() string

type Sections

type Sections struct {
	Tmpl []string

	ClauseTotal map[model.Status]int
	// contains filtered or unexported fields
}

Sections split sql into chunks

func NewSections

func NewSections() *Sections

NewSections create and initialize Sections

func (*Sections) BuildSQL

func (s *Sections) BuildSQL() ([]Clause, error)

BuildSQL sql sections and append to tmpl, return a Clause array

func (*Sections) GetName

func (s *Sections) GetName(status model.Status) string

GetName ...

func (*Sections) HasMore

func (s *Sections) HasMore() bool

HasMore: is has more section

func (*Sections) IsNull

func (s *Sections) IsNull() bool

IsNull whether section is empty

func (*Sections) SubIndex

func (s *Sections) SubIndex()

SubIndex take index one step back

type SetClause

type SetClause struct {
	Value []Clause
	// contains filtered or unexported fields
}

SetClause set clause

func (SetClause) Creat

func (s SetClause) Creat() string

func (SetClause) Finish

func (s SetClause) Finish(name string) string

func (SetClause) String

func (s SetClause) String() string

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

Jump to

Keyboard shortcuts

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