generate

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

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

type Clause interface {
	String() string
	Create() 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) Create

func (e ElseClause) Create() string

Create create clause

func (ElseClause) Finish

func (e ElseClause) Finish() string

Finish finish clause

func (ElseClause) String

func (e ElseClause) String() (res string)

type FieldParser

type FieldParser interface {
	GetFieldGenType(f *schema.Field) string
}

type ForClause

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

ForClause set clause

func (ForClause) Create

func (f ForClause) Create() string

Create create clause

func (ForClause) Finish

func (f ForClause) Finish() string

Finish finish clause

func (ForClause) String

func (f ForClause) String() string

type ForRange

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

ForRange for range clause for diy method

func (*ForRange) String

func (f *ForRange) String() string

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

func (IfClause) Create

func (i IfClause) Create() string

Create create clause

func (IfClause) Finish

func (i IfClause) Finish() string

Finish finish clause

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

func (m *InterfaceMethod) ReturnRowsAffected() bool

ReturnRowsAffected return rows affected

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
	InternalModelStructName string // internal struct name
	TableName               string // table name 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

func GetQueryStructMeta(db *gorm.DB, conf *model.Config) (*QueryStructMeta, error)

GetQueryStructMeta generate db model by table name

func GetQueryStructMetaFromObject

func GetQueryStructMetaFromObject(obj helper.Object, conf *model.Config) (*QueryStructMeta, error)

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

func (SQLClause) Create

func (s SQLClause) Create() string

Create create clause

func (SQLClause) Finish

func (s SQLClause) Finish() string

Finish finish clause

func (SQLClause) String

func (s SQLClause) String() string

type Section

type Section struct {
	Tmpls []string

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

Section split sql into chunks

func NewSection

func NewSection() *Section

NewSection create and initialize Sections

func (*Section) BuildSQL

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

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

func (*Section) GetName

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

GetName ...

func (*Section) HasMore

func (s *Section) HasMore() bool

HasMore is has more section

func (*Section) IsNull

func (s *Section) IsNull() bool

IsNull whether section is empty

func (*Section) SubIndex

func (s *Section) SubIndex()

SubIndex take index one step back

type SetClause

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

SetClause set clause

func (SetClause) Create

func (s SetClause) Create() string

Create create clause

func (SetClause) Finish

func (s SetClause) Finish(name string) string

Finish finish clause

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

func (w WhereClause) Create() string

Create create clause

func (WhereClause) Finish

func (w WhereClause) Finish(name string) string

Finish finish clause

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