Documentation ¶
Index ¶
- Constants
- Variables
- func ExecuteShell(cmdName string, cmdArgs []string) (ret string, err error)
- func FormatFieldName(s string) string
- func GenerateTemplate(tmplFile, outFile string, data interface{}) error
- func PathExists(path string) (bool, error)
- type Attribute
- type AutoIndex
- type Column
- type ColumnCfg
- type ColumnCfgType
- type ColumnDict
- type ColumnType
- type IndexCfg
- type ModelCfg
- type ModelMap
- type PackageCfg
- type QueryCfg
- type QueryMap
- type SqlRes
- type StructCfg
- type Table
- type TypeCfg
- type TypeDict
Constants ¶
View Source
const ( GormFieldTag_Type = "type" GormFieldTag_Size = "size" GormFieldTag_Primary = "primary" GormFieldTag_Unique = "unique" GormFieldTag_Default = "default" GormFieldTag_Precision = "precision" GormFieldTag_NotNull = "not_null" GormFieldTag_AutoIncrement = "auto_increment" GormFieldTag_Index = "index" GormFieldTag_UniqueIndex = "unique_index" )
View Source
const ( // 0单字段、1数组、2子结构体 ColumnCfgTypeSimple = 0 ColumnCfgTypeArray = 1 ColumnCfgTypeStruct = 2 )
View Source
const ( ColumnTypeInt8 = "int8" ColumnTypeUInt8 = "uint8" ColumnTypeInt16 = "int16" ColumnTypeUInt16 = "uint16" ColumnTypeInt32 = "int32" ColumnTypeUInt32 = "uint32" ColumnTypeInt64 = "int64" ColumnTypeUInt64 = "uint64" ColumnTypeFloat32 = "float32" ColumnTypeFloat64 = "float64" ColumnTypeBool = "bool" ColumnTypeVarchar = "varchar" ColumnTypeBinary = "blob" ColumnTypeDecimal = "decimal" ColumnTypeTime = "time" ColumnTypeDate = "date" ColumnTypeDateTime = "datetime" )
Constants for database(mysql) types
Variables ¶
View Source
var Debug = false
Debug level logging
Functions ¶
func ExecuteShell ¶
执行命令
func FormatFieldName ¶
FormatFieldName formats a string as a struct key
Example:
FormatFieldName("foo_id")
Output: FooID
func GenerateTemplate ¶
func PathExists ¶
Types ¶
type Attribute ¶
type Attribute map[string]interface{}
func (Attribute) GetAllGormTag ¶
func (Attribute) GetGormTag ¶
type Column ¶
type Column struct { Name string `json:"name"` // 字段名字 Note string `json:"note"` // 字段说明 Type ColumnType `json:"type"` // 字段类型 Attrs Attribute `json:"attrs"` // 字段属性 }
func (*Column) FormattedName ¶
func (*Column) GoTypeName ¶
type ColumnCfg ¶
type ColumnCfg struct { // "name", "type", "comment", "primary", "notnull", "unique", "auto_increment", "default" Name string // 字段名 Type string // 在yaml文件中的字段名 Comment string `yaml:"comment,omitempty"` // 字段说明,从属性表中抽出来的 Primary bool `yaml:"primary,omitempty"` // 是否是主键 NotNull bool `yaml:"notnull,omitempty"` // 是否不允许为空 Unique bool `yaml:"unique,omitempty"` // 是否必须唯一 AutoIncrement bool `yaml:"autoIncrement,omitempty"` // 是否自增 Default string `yaml:"default,omitempty"` // 默认值 GoType string `yaml:"goType,omitempty"` // 生成go代码时的type名 GoImport string `yaml:"goImport,omitempty"` // 生成go代码时的import路径 FieldType int `yaml:"fieldType,omitempty"` // 0单字段、1数组、2子结构体 //Type ColumnType `json:"type"` // column: name type comment default primary notnull unique auto_increment Attrs Attribute `yaml:"-" json:"attrs"` Children map[string]*ColumnCfg `yaml:"children,omitempty"` // 如果是子结构体,则包含子结构体的字段 }
字段配置
func NewColumnCfg ¶
func NewColumnCfg() *ColumnCfg
func (*ColumnCfg) GoImportsArray ¶
获取goimports导入数组
func (*ColumnCfg) GoImportsString ¶
获取goimports导入字符串,用换行符分割
type ColumnCfgType ¶
type ColumnCfgType int
type ColumnType ¶
type ColumnType string
type IndexCfg ¶
type IndexCfg struct { Name string // 索引名 Keys []string // 简单、结构体、数组 Comment string // 说明 Type string `yaml:"type,omitempty"` // 索引类型, index或unique }
索引配置
type ModelCfg ¶
type ModelCfg struct { // Struct StructCfg // model中的字段定义 Name string // 表明 Comment string // 表的说明 Columns []*ColumnCfg `yaml:"column"` // model中的字段定义 ColumnDict map[string]*ColumnCfg `yaml:"-"` // model中的字段定义 Indexes []*IndexCfg `yaml:"index"` // model中的索引定义 IndexDict map[string]*IndexCfg `yaml:"-"` // model中的索引定义 Query []*QueryCfg `yaml:"query"` // 包中的查询配置 QueryMap QueryMap `yaml:"-"` // 包中的查询配置 }
model定义
func NewModelCfg ¶
func NewModelCfg() *ModelCfg
func (*ModelCfg) GetGormIndexTag ¶
获取当前字段的gorm tag
func (*ModelCfg) GetGormTag ¶
获取字段的gorm tag,包含本身以及索引的
func (*ModelCfg) GoImportsString ¶
获取goimports导入字符串,用换行符分割
type PackageCfg ¶
type PackageCfg struct { Name string // 包名 Type []*TypeCfg `yaml:"type"` // 类型字典 TypeDict TypeDict `yaml:"-"` // 类型字典 Column []*ColumnCfg `yaml:"dict"` // 字段字典 ColumnDict ColumnDict `yaml:"-"` // 字段字典 Model []*ModelCfg `yaml:"model"` // 包中的model配置 ModelMap ModelMap `yaml:"-"` // 包中的model配置 CurrentModel *ModelCfg `yaml:"-"` // 包中的查询配置 CurrentQuery *QueryCfg `yaml:"-"` // 包中的查询配置 }
package 定义
func NewPackageCfg ¶
func NewPackageCfg() *PackageCfg
func ParseConfigure ¶
func ParseConfigure(file string) (*PackageCfg, error)
type QueryCfg ¶
type QueryCfg struct { Name string // 查询的名字 Comment string `yaml:"comment,omitempty"` // 查询的说明 SQLstr string `yaml:"sql,omitempty"` // 查询用到的sql语句 Pager bool `yaml:"pager,omitempty"` // 当sql为查询时,且输出为数组时,是否启用分页,默认不启用 In *StructCfg `yaml:"inputs,omitempty"` // 查询的输入参数 Out *StructCfg `yaml:"outputs,omitempty"` // 查询的输出参数 }
查询
func (*QueryCfg) FormatCountSQL ¶
func (*QueryCfg) GoImportsArray ¶
获取goimports导入数组
func (*QueryCfg) GoImportsString ¶
获取goimports导入字符串,用换行符分割
type StructCfg ¶
type StructCfg struct { Name string // 结构体名 Array bool // 输出是否为数组 Columns []*ColumnCfg `yaml:"column"` // 包含的字段 ColumnDict map[string]*ColumnCfg `yaml:"-"` // 包含的字段 }
结构体配置
func NewStructCfg ¶
func NewStructCfg() *StructCfg
func (*StructCfg) GoImportsArray ¶
获取goimports导入数组
func (*StructCfg) GoImportsString ¶
获取goimports导入字符串,用换行符分割
type Table ¶
type Table struct { Name string `json:"name"` // 表名 Note string `json:"note"` // 表的说明 Fields []Column `json:"fields"` // 所有字段 PrimaryKeys []string // 主键名数组,从Fields中提取出来的 Params []string `json:"params"` // 用于查询 Indexes []string `json:"indexes"` // 索引数组 AutoIndexes map[string]*AutoIndex `json:"AutoIndexes"` // 根据字段,自动建立的索引数组 }
func (*Table) GetModelFileName ¶
func (*Table) GetModelPath ¶
func (*Table) GetPrimaryIntKeys ¶
func (*Table) GetPrimaryStringKeys ¶
func (*Table) HasDateTimeField ¶
Click to show internal directories.
Click to hide internal directories.