tag insert
列注释添加tag
This commit is contained in:
6
Makefile
6
Makefile
@@ -1,11 +1,11 @@
|
|||||||
all: # 构建
|
all: # 构建
|
||||||
make tar
|
make tar
|
||||||
windows:
|
windows:
|
||||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gormt.exe main.go
|
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" -o gormt.exe main.go
|
||||||
mac:
|
mac:
|
||||||
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o gormt main.go
|
CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" -o gormt main.go
|
||||||
linux:
|
linux:
|
||||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o gormt main.go
|
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -o gormt main.go
|
||||||
tar: # 打包
|
tar: # 打包
|
||||||
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gormt.exe main.go
|
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o gormt.exe main.go
|
||||||
tar czvf gormt_windows.zip gormt.exe config.yml
|
tar czvf gormt_windows.zip gormt.exe config.yml
|
||||||
|
|||||||
@@ -199,6 +199,7 @@ CHCP 65001
|
|||||||
### table notes default
|
### table notes default
|
||||||
|
|
||||||
- Add a comment to the column starting with `[@gormt default:'test']`
|
- Add a comment to the column starting with `[@gormt default:'test']`
|
||||||
|
- example `[@gormt default:'test';->;<-:create]this is my notes` Indicates that the default value is 'test',can read/creat/write
|
||||||
|
|
||||||
## 9. one windows gui tools
|
## 9. one windows gui tools
|
||||||
|
|
||||||
|
|||||||
@@ -206,9 +206,10 @@ go generate
|
|||||||
CHCP 65001
|
CHCP 65001
|
||||||
```
|
```
|
||||||
|
|
||||||
### 表注释 default
|
### 表注释 tag
|
||||||
|
|
||||||
- 给列添加注释以`[@gormt default:'test']`开头即可
|
- 给列添加注释以`[@gormt default:'test']`开头即可
|
||||||
|
- 比如`[@gormt default:'test';->;<-:create]这是注释内容` 表示默认值为'test',允许读,更新创建
|
||||||
|
|
||||||
|
|
||||||
## 8. 下一步计划
|
## 8. 下一步计划
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ type ColumnsInfo struct {
|
|||||||
BaseInfo
|
BaseInfo
|
||||||
IsNull bool // null if db is set null
|
IsNull bool // null if db is set null
|
||||||
Type string // Type.类型标记
|
Type string // Type.类型标记
|
||||||
Default string // 默认值
|
Gormt string // 默认值
|
||||||
Index []KList // index list.index列表
|
Index []KList // index list.index列表
|
||||||
ForeignKeyList []ForeignKey // Foreign key list . 表的外键信息
|
ForeignKeyList []ForeignKey // Foreign key list . 表的外键信息
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,22 +53,13 @@ func GetModel() model.IModel {
|
|||||||
return &MySQLModel
|
return &MySQLModel
|
||||||
}
|
}
|
||||||
|
|
||||||
// FixElementNote 分析元素表注释
|
// FixElementTag 分析元素表注释
|
||||||
func FixElementNote(em *model.ColumnsInfo, note string) {
|
func FixElementTag(em *model.ColumnsInfo, note string) {
|
||||||
matches := noteRegex.FindStringSubmatch(note)
|
matches := noteRegex.FindStringSubmatch(note)
|
||||||
if len(matches) < 2 {
|
if len(matches) < 2 {
|
||||||
em.Notes = note
|
em.Notes = note
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
em.Notes = note[len(matches[0]):]
|
em.Notes = note[len(matches[0]):]
|
||||||
|
em.Gormt = matches[1]
|
||||||
list := strings.Split(matches[1], ";")
|
|
||||||
for _, v := range list {
|
|
||||||
tmp := strings.Split(v, ":")
|
|
||||||
if len(tmp) == 2 {
|
|
||||||
if strings.EqualFold(tmp[0], "default") { // 默认值
|
|
||||||
em.Default = tmp[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ func (m *mysqlModel) getTableElement(orm *mysqldb.MySqlDB, tab string) (el []mod
|
|||||||
var tmp model.ColumnsInfo
|
var tmp model.ColumnsInfo
|
||||||
tmp.Name = v.Field
|
tmp.Name = v.Field
|
||||||
tmp.Type = v.Type
|
tmp.Type = v.Type
|
||||||
FixElementNote(&tmp, v.Desc)
|
FixElementTag(&tmp, v.Desc) // 分析表注释
|
||||||
|
|
||||||
// keys
|
// keys
|
||||||
if keylist, ok := KeyColumnMp[v.Field]; ok { // maybe have index or key
|
if keylist, ok := KeyColumnMp[v.Field]; ok { // maybe have index or key
|
||||||
|
|||||||
@@ -53,22 +53,13 @@ func GetModel() model.IModel {
|
|||||||
return &SQLiteModel
|
return &SQLiteModel
|
||||||
}
|
}
|
||||||
|
|
||||||
// FixElementNote 分析元素表注释
|
// FixElementTag 分析元素表注释
|
||||||
func FixElementNote(em *model.ColumnsInfo, note string) {
|
func FixElementTag(em *model.ColumnsInfo, note string) {
|
||||||
matches := noteRegex.FindStringSubmatch(note)
|
matches := noteRegex.FindStringSubmatch(note)
|
||||||
if len(matches) < 2 {
|
if len(matches) < 2 {
|
||||||
em.Notes = note
|
em.Notes = note
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
em.Notes = note[len(matches[0]):]
|
em.Notes = note[len(matches[0]):]
|
||||||
|
em.Gormt = matches[1]
|
||||||
list := strings.Split(matches[1], ";")
|
|
||||||
for _, v := range list {
|
|
||||||
tmp := strings.Split(v, ":")
|
|
||||||
if len(tmp) == 2 {
|
|
||||||
if strings.EqualFold(tmp[0], "default") { // 默认值
|
|
||||||
em.Default = tmp[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ func (m *sqliteModel) getTableElement(orm *gorm.DB, tab string) (el []model.Colu
|
|||||||
var tmp model.ColumnsInfo
|
var tmp model.ColumnsInfo
|
||||||
tmp.Name = v.Name
|
tmp.Name = v.Name
|
||||||
tmp.Type = v.Type
|
tmp.Type = v.Type
|
||||||
FixElementNote(&tmp, "")
|
FixElementTag(&tmp, "")
|
||||||
if v.Pk == 1 { // 主键
|
if v.Pk == 1 { // 主键
|
||||||
tmp.Index = append(tmp.Index, model.KList{
|
tmp.Index = append(tmp.Index, model.KList{
|
||||||
Key: model.ColumnsKeyPrimary,
|
Key: model.ColumnsKeyPrimary,
|
||||||
|
|||||||
@@ -108,8 +108,8 @@ func (m *_Model) genTableElement(cols []ColumnsInfo) (el []genstruct.GenElement)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// default tag
|
// default tag
|
||||||
if len(v.Default) > 0 {
|
if len(v.Gormt) > 0 {
|
||||||
tmp.AddTag(_tagGorm, "default:"+v.Default)
|
tmp.AddTag(_tagGorm, v.Gormt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// json tag
|
// json tag
|
||||||
|
|||||||
Reference in New Issue
Block a user