new
This commit is contained in:
@@ -62,7 +62,11 @@ db_info:
|
|||||||
password : qwer
|
password : qwer
|
||||||
database : oauth_db
|
database : oauth_db
|
||||||
type: 0 # 数据库类型:0:mysql , 1:sqlite , 2:mssql
|
type: 0 # 数据库类型:0:mysql , 1:sqlite , 2:mssql
|
||||||
|
self_type_define: # 自定义数据类型映射
|
||||||
|
datetime: time.Time
|
||||||
|
date: time.Time
|
||||||
|
out_file_name: "" # 自定义生成文件名
|
||||||
|
web_tag_type: 0 # json tag类型 0: 小驼峰 1: 下划线
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ db_info:
|
|||||||
password : 123456
|
password : 123456
|
||||||
database : matrix
|
database : matrix
|
||||||
type: 0 # 数据库类型:0:mysql , 1:sqlite , 2:mssql
|
type: 0 # 数据库类型:0:mysql , 1:sqlite , 2:mssql
|
||||||
self_define_type_mysql_dic_map: # 自定义数据类型映射
|
self_type_define: # 自定义数据类型映射
|
||||||
datetime: time.Time
|
datetime: time.Time
|
||||||
date: time.Time
|
time: time.Time
|
||||||
out_file_name: "" # 自定义生成文件名
|
out_file_name: "" # 自定义生成文件名
|
||||||
web_tag_type: 0 # json tag类型 0: 下划线 1: 小驼峰
|
web_tag_type: 0 # json tag类型 0: 小驼峰 1: 下划线
|
||||||
|
|
||||||
# sqlite
|
# sqlite
|
||||||
# db_info:
|
# db_info:
|
||||||
|
|||||||
@@ -9,24 +9,24 @@ import (
|
|||||||
// Config custom config struct
|
// Config custom config struct
|
||||||
type Config struct {
|
type Config struct {
|
||||||
CfgBase `yaml:"base"`
|
CfgBase `yaml:"base"`
|
||||||
DBInfo DBInfo `yaml:"db_info"`
|
DBInfo DBInfo `yaml:"db_info"`
|
||||||
OutDir string `yaml:"out_dir"`
|
OutDir string `yaml:"out_dir"`
|
||||||
URLTag string `yaml:"url_tag"` // url tag
|
URLTag string `yaml:"url_tag"` // url tag
|
||||||
Language string `yaml:"language"` // language
|
Language string `yaml:"language"` // language
|
||||||
DbTag string `yaml:"db_tag"` // 数据库标签(gormt,db)
|
DbTag string `yaml:"db_tag"` // 数据库标签(gormt,db)
|
||||||
Simple bool `yaml:"simple"`
|
Simple bool `yaml:"simple"`
|
||||||
IsWEBTag bool `yaml:"is_web_tag"`
|
IsWEBTag bool `yaml:"is_web_tag"`
|
||||||
IsWebTagPkHidden bool `yaml:"is_web_tag_pk_hidden"` // web标记是否隐藏主键
|
IsWebTagPkHidden bool `yaml:"is_web_tag_pk_hidden"` // web标记是否隐藏主键
|
||||||
IsForeignKey bool `yaml:"is_foreign_key"`
|
IsForeignKey bool `yaml:"is_foreign_key"`
|
||||||
IsOutSQL bool `yaml:"is_out_sql"`
|
IsOutSQL bool `yaml:"is_out_sql"`
|
||||||
IsOutFunc bool `yaml:"is_out_func"`
|
IsOutFunc bool `yaml:"is_out_func"`
|
||||||
IsGUI bool `yaml:"is_gui"` //
|
IsGUI bool `yaml:"is_gui"` //
|
||||||
IsTableName bool `yaml:"is_table_name"`
|
IsTableName bool `yaml:"is_table_name"`
|
||||||
IsNullToPoint bool `yaml:"is_null_to_point"` // null to porint
|
IsNullToPoint bool `yaml:"is_null_to_point"` // null to porint
|
||||||
TablePrefix string `yaml:"table_prefix"` // 表前缀
|
TablePrefix string `yaml:"table_prefix"` // 表前缀
|
||||||
SelfDefineTypeMysqlDicMap map[string]string `yaml:"self_define_type_mysql_dic_map"`
|
SelfTypeDef map[string]string `yaml:"self_type_define"`
|
||||||
OutFileName string `yaml:"out_file_name"`
|
OutFileName string `yaml:"out_file_name"`
|
||||||
WebTagType int `yaml:"web_tag_type"`
|
WebTagType int `yaml:"web_tag_type"` // 默认小驼峰
|
||||||
}
|
}
|
||||||
|
|
||||||
// DBInfo mysql database information. mysql 数据库信息
|
// DBInfo mysql database information. mysql 数据库信息
|
||||||
@@ -225,18 +225,18 @@ func GetTablePrefix() string {
|
|||||||
return _map.TablePrefix
|
return _map.TablePrefix
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetSelfDefineTypeMysqlDicMap 设置自定义字段映射
|
// SetSelfTypeDefine 设置自定义字段映射
|
||||||
func SetSelfDefineTypeMysqlDicMap(data map[string]string) {
|
func SetSelfTypeDefine(data map[string]string) {
|
||||||
_map.SelfDefineTypeMysqlDicMap = data
|
_map.SelfTypeDef = data
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSelfDefineTypeMysqlDicMap 获取自定义字段映射
|
// GetSelfTypeDefine 获取自定义字段映射
|
||||||
func GetSelfDefineTypeMysqlDicMap() map[string]string {
|
func GetSelfTypeDefine() map[string]string {
|
||||||
return _map.SelfDefineTypeMysqlDicMap
|
return _map.SelfTypeDef
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetOutFileName 设置输出文件名
|
// SetOutFileName 设置输出文件名
|
||||||
func SetOutFileName(s string) {
|
func SetOutFileName(s string) {
|
||||||
_map.OutFileName = s
|
_map.OutFileName = s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,9 +44,8 @@ var _map = Config{
|
|||||||
IsOutFunc: true,
|
IsOutFunc: true,
|
||||||
IsGUI: false,
|
IsGUI: false,
|
||||||
TablePrefix: "",
|
TablePrefix: "",
|
||||||
SelfDefineTypeMysqlDicMap: make(map[string]string),
|
SelfTypeDef: make(map[string]string),
|
||||||
OutFileName: "",
|
WebTagType: 0,
|
||||||
WebTagType: 0,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var configPath string
|
var configPath string
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ func FilterKeywords(src string) string {
|
|||||||
// getTypeName Type acquisition filtering.类型获取过滤
|
// getTypeName Type acquisition filtering.类型获取过滤
|
||||||
func getTypeName(name string, isNull bool) string {
|
func getTypeName(name string, isNull bool) string {
|
||||||
// 优先匹配自定义类型
|
// 优先匹配自定义类型
|
||||||
selfDefineTypeMqlDicMap := config.GetSelfDefineTypeMysqlDicMap()
|
selfDefineTypeMqlDicMap := config.GetSelfTypeDefine()
|
||||||
if v, ok := selfDefineTypeMqlDicMap[name]; ok {
|
if v, ok := selfDefineTypeMqlDicMap[name]; ok {
|
||||||
return fixNullToPorint(v, isNull)
|
return fixNullToPorint(v, isNull)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,10 @@ func Generate(info DBInfo) (out []GenOutInfo, m _Model) {
|
|||||||
// struct
|
// struct
|
||||||
var stt GenOutInfo
|
var stt GenOutInfo
|
||||||
stt.FileCtx = m.generate()
|
stt.FileCtx = m.generate()
|
||||||
if name := config.GetOutFileName(); name != "" {
|
stt.FileName = info.DbName + ".go"
|
||||||
|
|
||||||
|
if name := config.GetOutFileName(); len(name) > 0 {
|
||||||
stt.FileName = name + ".go"
|
stt.FileName = name + ".go"
|
||||||
} else {
|
|
||||||
stt.FileName = info.DbName + ".go"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out = append(out, stt)
|
out = append(out, stt)
|
||||||
@@ -136,9 +136,9 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
|
|||||||
tmp.AddTag(_tagJSON, "-")
|
tmp.AddTag(_tagJSON, "-")
|
||||||
} else {
|
} else {
|
||||||
if config.GetWebTagType() == 0 {
|
if config.GetWebTagType() == 0 {
|
||||||
tmp.AddTag(_tagJSON, mybigcamel.UnMarshal(v.Name))
|
|
||||||
} else {
|
|
||||||
tmp.AddTag(_tagJSON, mybigcamel.UnSmallMarshal(mybigcamel.Marshal(v.Name)))
|
tmp.AddTag(_tagJSON, mybigcamel.UnSmallMarshal(mybigcamel.Marshal(v.Name)))
|
||||||
|
} else {
|
||||||
|
tmp.AddTag(_tagJSON, mybigcamel.UnMarshal(v.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,11 +183,10 @@ func (m *_Model) genForeignKey(col ColumnsInfo) (fklist []genstruct.GenElement)
|
|||||||
// json tag
|
// json tag
|
||||||
if config.GetIsWEBTag() {
|
if config.GetIsWEBTag() {
|
||||||
if config.GetWebTagType() == 0 {
|
if config.GetWebTagType() == 0 {
|
||||||
tmp.AddTag(_tagJSON, mybigcamel.UnMarshal(v.TableName)+"_list")
|
|
||||||
} else {
|
|
||||||
tmp.AddTag(_tagJSON, mybigcamel.UnSmallMarshal(mybigcamel.Marshal(v.TableName))+"List")
|
tmp.AddTag(_tagJSON, mybigcamel.UnSmallMarshal(mybigcamel.Marshal(v.TableName))+"List")
|
||||||
|
} else {
|
||||||
|
tmp.AddTag(_tagJSON, mybigcamel.UnMarshal(v.TableName)+"_list")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fklist = append(fklist, tmp)
|
fklist = append(fklist, tmp)
|
||||||
|
|||||||
Reference in New Issue
Block a user