Documentation ¶
Index ¶
- Constants
- Variables
- func AmendComments(db *sql.DB, opts Options, verbose bool) error
- func CheckError(err error) bool
- func CollectCode(opts Options, outname string, verbose bool) (err error)
- func CreateModels(conf *Config, db *gorm.DB, mode uint) (names []string, err error)
- func FindTables(db *sql.DB, verbose bool) ([]string, []map[string]string)
- func GenInitFile(conf *Config, names []string, mode uint) (err error)
- func GenNameType(col *schema.ColumnInfo, rule RuleConfig, nps map[string]NullPointer) string
- func GenTagComment(col *schema.ColumnInfo, rule RuleConfig) string
- func GetTemplate(funcMap template.FuncMap, name, fname string, others ...string) *template.Template
- func NullPointerMatch(nps map[string]NullPointer, rule RuleConfig, ci *schema.ColumnInfo) bool
- func ParseModelComments(filename, prefix string, verbose bool) (map[string]string, map[string](map[string]string))
- func ToCamel(name string) string
- func ToPlural(name string) string
- func ToSingular(name string) string
- func ToSnake(name string) string
- func WriteInitFile(buf bytes.Buffer, fname, driverName string) error
- func WriteModelFile(buf bytes.Buffer, fname string) error
- type AppConfig
- type Config
- type ConnConfig
- type Logger
- type NullPointer
- type Options
- type RuleConfig
- type TableRuleConfig
Constants ¶
View Source
const ( MODE_SAFE uint = iota MODE_INIT MODE_TWO_FILES MODE_THREE_FILES MODE_QUERY_DISTRI MODE_TABLE_DISTRI )
View Source
const DIR_MODE = 0777
Variables ¶
View Source
var ( TemplateNotFound = errors.New("template not found") TemplateModeIntros = map[uint]string{ MODE_SAFE: "安全模式,与 5 类似,但会在每个文件名前面加一个下划线", MODE_INIT: "只生成 init.go 文件", MODE_TWO_FILES: "除了 init.go 文件, table 和 query 都放入 tables.go 中", MODE_THREE_FILES: "除了 init.go 文件, table 都放入 tables.go 中, query 都放入 queries.go 中", MODE_QUERY_DISTRI: "除了 init.go 文件, table 都放入 tables.go 中, query 分开放入对应模型名文件中", MODE_TABLE_DISTRI: "除了 init.go 文件, table 和 query 一起放入对应模型名文件中", } )
Functions ¶
func AmendComments ¶
将代码中的表和字段注释,覆盖数据库的SQL语句注释
func CollectCode ¶
在目录下所有的go代码中,找出baseModel子类的完整代码写入一个文件
func CreateModels ¶
func FindTables ¶
找出所有表名,并列出每张表的字段定义
func GenNameType ¶ added in v0.5.5
func GenNameType(col *schema.ColumnInfo, rule RuleConfig, nps map[string]NullPointer) string
func GenTagComment ¶ added in v0.5.5
func GenTagComment(col *schema.ColumnInfo, rule RuleConfig) string
func GetTemplate ¶ added in v0.5.5
func NullPointerMatch ¶ added in v0.6.3
func NullPointerMatch(nps map[string]NullPointer, rule RuleConfig, ci *schema.ColumnInfo) bool
func ParseModelComments ¶
func ParseModelComments(filename, prefix string, verbose bool) (map[string]string, map[string](map[string]string))
分析文件代码,找出所有Model注释和其中的字段注释
func ToSingular ¶ added in v0.5.7
func WriteInitFile ¶ added in v0.6.2
Types ¶
type AppConfig ¶
type AppConfig struct { Debug bool `toml:"debug"` OutputDir string `toml:"output_dir"` // 输出目录,例如 models DataFile string `toml:"data_file"` // 数据文件,例如 data.toml PluralTable bool `toml:"plural_table"` // 表名使用复数形式 }
应用配置
type Config ¶
type Config struct { FileName string // 文件名 ConnName string // 连接名 Application AppConfig Connections map[string]ConnConfig NullPointers map[string]NullPointer `toml:"null_pointers"` ModelRules map[string]TableRuleConfig `toml:"model_rules"` }
配置
func (Config) GetDriverName ¶ added in v0.5.5
func (Config) GetRules ¶ added in v0.4.3
func (c Config) GetRules(table string) (rules TableRuleConfig)
func (Config) GetTablePrefix ¶ added in v0.5.5
type ConnConfig ¶
type ConnConfig struct { Driver string `toml:"driver"` Prefix string `toml:"prefix"` redisw.ConnParams }
连接配置
type NullPointer ¶ added in v0.6.3
type NullPointer struct { UsePointer bool `toml:"use_pointer"` // 是否使用指针类型 MustIndex bool `toml:"must_index"` // 如果使用指针类型,字段必须是索引 MinLength int `toml:"min_length"` // 如果使用指针类型,字段长度最少为多大 }
NULL字段使用指针类型
func (NullPointer) MatchCond ¶ added in v0.6.3
func (np NullPointer) MatchCond(ci *schema.ColumnInfo) bool
type RuleConfig ¶ added in v0.4.3
type RuleConfig struct { Name string `toml:"name"` Type string `toml:"type"` Json string `toml:"json"` Tags string `toml:"tags"` Comment string `toml:"comment"` }
规则配置
func GetRule ¶ added in v0.5.5
func GetRule(rules TableRuleConfig, name string) RuleConfig
type TableRuleConfig ¶ added in v0.4.3
type TableRuleConfig = map[string]RuleConfig
Click to show internal directories.
Click to hide internal directories.