model

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2024 License: MIT, MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

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

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

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

AddMethodOpt diy method option

func (AddMethodOpt) Methods

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

Methods ...

func (AddMethodOpt) OptionType

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

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

GetDataType get data type

func (*Column) SetDataTypeMap

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

SetDataTypeMap set data type map

func (*Column) ToField

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

ToField convert to field

func (*Column) WithNS

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

WithNS with name strategy

type Config

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

	ImportPkgPaths []string
	ModelOpts      []Option

	NameStrategy
	FieldConfig
	MethodConfig
}

Config model configuration

func (*Config) GetModelMethods

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

GetModelMethods get diy method from option

func (*Config) GetNames

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

GetNames get names

func (*Config) GetSchemaName

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

GetSchemaName get schema name

func (*Config) Preprocess

func (cfg *Config) Preprocess() *Config

Preprocess revise invalid field

type CreateFieldOpt

type CreateFieldOpt ModifyFieldOpt

CreateFieldOpt create field option

func (CreateFieldOpt) Operator

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

Operator implement for FieldOpt

func (CreateFieldOpt) OptionType

func (CreateFieldOpt) OptionType() string

OptionType implement for interface Option

type Field

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

Field user input structures

func (*Field) EscapeKeyword

func (m *Field) EscapeKeyword() *Field

EscapeKeyword escape keyword

func (*Field) EscapeKeywordFor

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

EscapeKeywordFor escape for specified keyword

func (*Field) GenType

func (m *Field) GenType() string

GenType ...

func (*Field) IsRelation

func (m *Field) IsRelation() bool

IsRelation ...

func (*Field) Tags

func (m *Field) Tags() string

Tags ...

type FieldConfig

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

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

FieldOption ...

type FilterFieldOpt

type FilterFieldOpt ModifyFieldOpt

FilterFieldOpt filter field option

func (FilterFieldOpt) Operator

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

Operator implement for FieldOpt

func (FilterFieldOpt) OptionType

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

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

KeyWord ...

func (*KeyWord) Contain

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

Contain contain

func (*KeyWord) FullMatch

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

FullMatch full match

type MethodConfig

type MethodConfig struct {
	MethodOpts []MethodOption
}

MethodConfig method configuration

type MethodOption

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

MethodOption ...

type ModifyFieldOpt

type ModifyFieldOpt func(*Field) *Field

ModifyFieldOpt modify field option

func (ModifyFieldOpt) Operator

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

Operator implement for FieldOpt

func (ModifyFieldOpt) OptionType

func (ModifyFieldOpt) OptionType() string

OptionType implement for interface Option

type NameStrategy

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

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

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