model

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Functions

func GroupByColumn

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

Types

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)

func (*Column) SetDataTypeMap

func (c *Column) SetDataTypeMap(m map[string]func(detailType string) (dataType string))

func (*Column) ToField

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

func (*Column) WithNS

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

type Conf

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

	ImportPkgPaths []string

	SchemaNameOpts []SchemaNameOpt
	TableNameNS    func(tableName string) string
	ModelNameNS    func(tableName string) string
	FileNameNS     func(tableName string) string

	FieldConf
}

Conf model configuration

func (*Conf) GetSchemaName

func (cf *Conf) GetSchemaName(db *gorm.DB) string

func (*Conf) SortOpt

func (cf *Conf) SortOpt() (modifyOpts []FieldOpt, filterOpts []FieldOpt, createOpts []FieldOpt)

type CreateFieldOpt

type CreateFieldOpt ModifyFieldOpt

func (CreateFieldOpt) Operator

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

type Field

type Field struct {
	Name             string
	Type             string
	ColumnName       string
	ColumnComment    string
	MultilineComment bool
	JSONTag          string
	GORMTag          string
	NewTag           string
	OverwriteTag     string

	Relation *field.Relation
}

Field user input structures

func (*Field) EscapeKeyword

func (m *Field) EscapeKeyword() *Field

func (*Field) GenType

func (m *Field) GenType() string

func (*Field) IsRelation

func (m *Field) IsRelation() bool

func (*Field) Tags

func (m *Field) Tags() string

type FieldConf

type FieldConf struct {
	DataTypeMap map[string]func(detailType string) (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
	FieldNewTagNS  func(columnName string) string

	FieldOpts []FieldOpt
}

FieldConf field configuration

type FieldOpt

type FieldOpt interface{ Operator() func(*Field) *Field }

type FilterFieldOpt

type FilterFieldOpt ModifyFieldOpt

func (FilterFieldOpt) Operator

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

type Index

type Index struct {
	TableName  string `gorm:"column:TABLE_NAME"`
	ColumnName string `gorm:"column:COLUMN_NAME"`
	IndexName  string `gorm:"column:INDEX_NAME"`
	SeqInIndex int32  `gorm:"column:SEQ_IN_INDEX"`
	NonUnique  int32  `gorm:"column:NON_UNIQUE"`
}

Index table index info

func (*Index) IsPrimaryKey

func (c *Index) IsPrimaryKey() bool

func (*Index) IsUnique

func (c *Index) IsUnique() bool

not primary key but unique key

type KeyWords

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

func (*KeyWords) Contain

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

func (*KeyWords) FullMatch

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

type ModifyFieldOpt

type ModifyFieldOpt func(*Field) *Field

func (ModifyFieldOpt) Operator

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

type SQLBuffer

type SQLBuffer struct{ bytes.Buffer }

func (*SQLBuffer) Dump

func (s *SQLBuffer) Dump() string

func (*SQLBuffer) WriteSql

func (s *SQLBuffer) WriteSql(b byte)

type SchemaNameOpt

type SchemaNameOpt func(*gorm.DB) string

type SourceCode

type SourceCode int
const (
	Struct SourceCode = iota
	Table
	Object
)

type Status

type Status int
const (
	UNKNOWN Status = iota
	SQL
	DATA
	VARIABLE
	IF
	ELSE
	WHERE
	SET
	FOR
	END
)

Jump to

Keyboard shortcuts

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