Documentation ¶
Index ¶
- Constants
- Variables
- func OutputTemplate(dir string) error
- type Config
- type GenerateMode
- type Generator
- func (g *Generator) ApplyBasic(models ...interface{})
- func (g *Generator) ApplyInterface(fc interface{}, models ...interface{})
- func (g *Generator) Execute()
- func (g *Generator) GenerateAllTable() (tableModels []interface{})
- func (g *Generator) GenerateModel(tableName string) *generate.StructMeta
- func (g *Generator) GenerateModelAs(tableName string, modelName string) *generate.StructMeta
- func (g *Generator) UseDB(db *gorm.DB)
- type M
- type RowsAffected
- type SQLResult
- type SQLRow
- type SQLRows
- type T
- type Template
Constants ¶
View Source
const TemplateName = "template"
View Source
const TemplatePrefix = "*tpl"
Variables ¶
View Source
var ( // ErrEmptyCondition empty condition ErrEmptyCondition = errors.New("empty condition") )
View Source
var (
ErrFileExist = errors.New("file exist skip overwrite")
)
View Source
var TemplateFs embed.FS
Functions ¶
func OutputTemplate ¶
Types ¶
type Config ¶
type Config struct { // generate model global configuration FieldNullable bool // generate pointer when field is nullable FieldCoverable bool // generate pointer when field has default value, to fix problem zero value cannot be assign: https://gorm.io/docs/create.html#Default-Values FieldSignable bool // detect integer field's unsigned type, adjust generated data type Mode GenerateMode // generate mode QueryPkgName string // generated query code's package name TemplateDir string // generated with template directory FieldWithTags []string // generate field with custom tag Overwrite bool // overwrite existing file DefaultAllTable bool // 默认全部表 TableRegexp string // table regexp TableRegexpStyle string // table regexp style ModelName string // model 名称 Templates []Template // dynamic const suffix DynamicConstSuffixes []string // dynamic const suffix DynamicConstOutPath string // dynamic const out path DynamicConstTemplate string // 动态常量模板 DynamicAliasSuffix string // 动态常量包别名后缀 DynamicConstImport bool // 动态常量自动导入 AutoValueFields []string // dynamic const suffix ConvTypeMap map[string]string `yaml:"convType"` // conv type ConvTypePkgMap map[string]string `yaml:"convTypePkg"` // conv type pkg // contains filtered or unexported fields }
Config generator's basic configuration
func (*Config) WithJSONTagNameStrategy ¶
WithJSONTagNameStrategy specify json tag naming strategy
type GenerateMode ¶
type GenerateMode uint
GenerateMode generate mode
const ( // WithDefaultQuery create default query in generated code WithDefaultQuery GenerateMode = 1 << iota // WithoutContext generate code without context constrain WithoutContext // WithQueryInterface generate code with exported interface object WithQueryInterface )
type Generator ¶
type Generator struct { Config Data map[string]*genInfo //gen query data // contains filtered or unexported fields }
Generator code generator
func (*Generator) ApplyBasic ¶
func (g *Generator) ApplyBasic(models ...interface{})
ApplyBasic specify models which will implement basic .diy_method
func (*Generator) ApplyInterface ¶
func (g *Generator) ApplyInterface(fc interface{}, models ...interface{})
ApplyInterface specifies .diy_method interfaces on structures, implment codes will be generated after calling g.Execute() eg: g.ApplyInterface(func(model.Method){}, model.User{}, model.Company{})
func (*Generator) GenerateAllTable ¶
func (g *Generator) GenerateAllTable() (tableModels []interface{})
GenerateAllTable generate all tables in db
func (*Generator) GenerateModel ¶
func (g *Generator) GenerateModel(tableName string) *generate.StructMeta
GenerateModel catch table info from db, return a BaseStruct
func (*Generator) GenerateModelAs ¶
func (g *Generator) GenerateModelAs(tableName string, modelName string) *generate.StructMeta
GenerateModelAs catch table info from db, return a BaseStruct
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
utils/pools
Package pools : goroutine pools
|
Package pools : goroutine pools |
tools
|
|
gentool
Module
|
Click to show internal directories.
Click to hide internal directories.