model

package
v0.3.26 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultModelPkg ...
	DefaultModelPkg = "model"
)

Variables

View Source
var DOKeywords = KeyWord{
	// contains filtered or unexported fields
}

DOKeywords ...

View Source
var GenKeywords = KeyWord{
	// contains filtered or unexported fields
}

GenKeywords ...

View Source
var GormKeywords = KeyWord{
	// contains filtered or unexported fields
}

GormKeywords ...

Functions

func GroupByColumn

func GroupByColumn(indexList []gorm.Index) map[string][]*Index

GroupByColumn group columns

Types

type AddMethodOpt added in v0.3.14

type AddMethodOpt func() (methods []interface{})

AddMethodOpt diy method option

func (AddMethodOpt) Methods added in v0.3.14

func (o AddMethodOpt) Methods() []interface{}

Methods ...

func (AddMethodOpt) OptionType added in v0.3.14

func (AddMethodOpt) OptionType() string

OptionType implement for interface Option

type Column

type Column struct {
	gorm.ColumnType
	TableName   string   `gorm:"column:TABLE_NAME"`
	Indexes     []*Index `gorm:"-"`
	UseScanType bool     `gorm:"-"`
	// contains filtered or unexported fields
}

Column table column's info

func (*Column) GetDataType added in v0.1.20

func (c *Column) GetDataType() (fieldtype string)

GetDataType get data type

func (*Column) SetDataTypeMap added in v0.1.20

func (c *Column) SetDataTypeMap(m map[string]func(columnType gorm.ColumnType) (dataType string))

SetDataTypeMap set data type map

func (*Column) ToField added in v0.2.27

func (c *Column) ToField(nullable, coverable, signable bool) *Field

ToField convert to field

func (*Column) WithNS added in v0.1.26

func (c *Column) WithNS(jsonTagNS func(columnName string) string)

WithNS with name strategy

type Config added in v0.3.9

type Config struct {
	ModelPkg    string
	TablePrefix string
	TableName   string
	ModelName   string

	ImportPkgPaths []string
	ModelOpts      []Option

	NameStrategy
	FieldConfig
	MethodConfig
}

Config model configuration

func (*Config) GetModelMethods added in v0.3.14

func (cfg *Config) GetModelMethods() (methods []interface{})

GetModelMethods get diy method from option

func (*Config) GetNames added in v0.3.9

func (cfg *Config) GetNames() (tableName, structName, fileName string)

GetNames get names

func (*Config) GetSchemaName added in v0.3.9

func (cfg *Config) GetSchemaName(db *gorm.DB) string

GetSchemaName get schema name

func (*Config) Preprocess added in v0.3.14

func (cfg *Config) Preprocess() *Config

Preprocess revise invalid field

type CreateFieldOpt added in v0.2.27

type CreateFieldOpt ModifyFieldOpt

CreateFieldOpt create field option

func (CreateFieldOpt) Operator added in v0.2.27

func (o CreateFieldOpt) Operator() func(*Field) *Field

Operator implement for FieldOpt

func (CreateFieldOpt) OptionType added in v0.3.14

func (CreateFieldOpt) OptionType() string

OptionType implement for interface Option

type Field added in v0.2.27

type Field struct {
	Name             string
	Type             string
	ColumnName       string
	ColumnComment    string
	MultilineComment bool
	Tag              field.Tag
	GORMTag          field.GormTag
	CustomGenType    string
	Relation         *field.Relation
}

Field user input structures

func (*Field) EscapeKeyword added in v0.2.27

func (m *Field) EscapeKeyword() *Field

EscapeKeyword escape keyword

func (*Field) EscapeKeywordFor added in v0.3.17

func (m *Field) EscapeKeywordFor(keywords KeyWord) *Field

EscapeKeywordFor escape for specified keyword

func (*Field) GenType added in v0.2.27

func (m *Field) GenType() string

GenType ...

func (*Field) IsRelation added in v0.2.27

func (m *Field) IsRelation() bool

IsRelation ...

func (*Field) Tags added in v0.3.0

func (m *Field) Tags() string

Tags ...

type FieldConfig added in v0.3.9

type FieldConfig struct {
	DataTypeMap map[string]func(columnType gorm.ColumnType) (dataType string)

	FieldNullable     bool // generate pointer when field is nullable
	FieldCoverable    bool // generate pointer when field has default value
	FieldSignable     bool // detect integer field's unsigned type, adjust generated data type
	FieldWithIndexTag bool // generate with gorm index tag
	FieldWithTypeTag  bool // generate with gorm column type tag

	FieldJSONTagNS func(columnName string) string

	ModifyOpts []FieldOption
	FilterOpts []FieldOption
	CreateOpts []FieldOption
}

FieldConfig field configuration

type FieldOption added in v0.3.14

type FieldOption interface {
	Option
	Operator() func(*Field) *Field
}

FieldOption ...

type FilterFieldOpt added in v0.2.27

type FilterFieldOpt ModifyFieldOpt

FilterFieldOpt filter field option

func (FilterFieldOpt) Operator added in v0.2.27

func (o FilterFieldOpt) Operator() func(*Field) *Field

Operator implement for FieldOpt

func (FilterFieldOpt) OptionType added in v0.3.14

func (FilterFieldOpt) OptionType() string

OptionType implement for interface Option

type Index

type Index struct {
	gorm.Index
	Priority int32 `gorm:"column:SEQ_IN_INDEX"`
}

Index table index info

type KeyWord added in v0.3.9

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

KeyWord ...

func (*KeyWord) Contain added in v0.3.9

func (g *KeyWord) Contain(text string) bool

Contain contain

func (*KeyWord) FullMatch added in v0.3.9

func (g *KeyWord) FullMatch(word string) bool

FullMatch full match

type MethodConfig added in v0.3.14

type MethodConfig struct {
	MethodOpts []MethodOption
}

MethodConfig method configuration

type MethodOption added in v0.3.14

type MethodOption interface {
	Option
	Methods() (methods []interface{})
}

MethodOption ...

type ModifyFieldOpt added in v0.2.27

type ModifyFieldOpt func(*Field) *Field

ModifyFieldOpt modify field option

func (ModifyFieldOpt) Operator added in v0.2.27

func (o ModifyFieldOpt) Operator() func(*Field) *Field

Operator implement for FieldOpt

func (ModifyFieldOpt) OptionType added in v0.3.14

func (ModifyFieldOpt) OptionType() string

OptionType implement for interface Option

type NameStrategy added in v0.3.10

type NameStrategy struct {
	SchemaNameOpts []SchemaNameOpt

	TableNameNS func(tableName string) string
	ModelNameNS func(tableName string) string
	FileNameNS  func(tableName string) string
}

NameStrategy name strategy

type Option added in v0.3.14

type Option interface{ OptionType() string }

Option field option

type SQLBuffer

type SQLBuffer struct{ bytes.Buffer }

SQLBuffer sql buffer

func (*SQLBuffer) Dump

func (s *SQLBuffer) Dump() string

Dump ...

func (*SQLBuffer) WriteSQL added in v0.3.9

func (s *SQLBuffer) WriteSQL(b byte)

WriteSQL ...

type SchemaNameOpt

type SchemaNameOpt func(*gorm.DB) string

SchemaNameOpt schema name option

type SourceCode

type SourceCode int

SourceCode source code

const (
	// Struct ...
	Struct SourceCode = iota
	// Table ...
	Table
	// Object ...
	Object
)

type Status

type Status int

Status sql status

const (
	// UNKNOWN ...
	UNKNOWN Status = iota
	// SQL ...
	SQL
	// DATA ...
	DATA
	// VARIABLE ...
	VARIABLE
	// IF ...
	IF
	// ELSE ...
	ELSE
	// WHERE ...
	WHERE
	// SET ...
	SET
	// FOR ...
	FOR
	// END ...
	END
	// TRIM ...
	TRIM
)

Jump to

Keyboard shortcuts

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