Browse Source

Merge pull request #51 from araragitsukihiz/master

add ignoreColumnsJSON
pull/58/head
Lunny Xiao GitHub 1 year ago
parent
commit
08263eb02c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 3 deletions
  1. +14
    -1
      xorm/go.go
  2. +6
    -1
      xorm/reverse.go
  3. +2
    -1
      xorm/templates/go/config

+ 14
- 1
xorm/go.go View File

@@ -290,7 +290,11 @@ func tag(table *core.Table, col *core.Column) string {

var tags []string
if genJson {
tags = append(tags, "json:\""+col.Name+"\"")
if b := isIgnore(col.Name, ignoreColumnsJSON); b {
tags = append(tags, "json:\"-\"")
} else {
tags = append(tags, "json:\""+col.Name+"\"")
}
}
if len(res) > 0 {
tags = append(tags, "xorm:\""+strings.Join(res, " ")+"\"")
@@ -301,3 +305,12 @@ func tag(table *core.Table, col *core.Column) string {
return ""
}
}

func isIgnore(col string, ignoreColumnsJSON []string) bool {
for i := 0; i < len(ignoreColumnsJSON); i++ {
if ignoreColumnsJSON[i] == col {
return true
}
}
return false
}

+ 6
- 1
xorm/reverse.go View File

@@ -51,7 +51,8 @@ func init() {
}

var (
genJson bool = false
genJson bool = false
ignoreColumnsJSON []string = []string{}
)

func printReversePrompt(flag string) {
@@ -156,6 +157,10 @@ func runReverse(cmd *Command, args []string) {
if j, ok := configs["prefix"]; ok {
prefix = j
}

if j, ok := configs["ignoreColumnsJSON"]; ok {
ignoreColumnsJSON = strings.Split(j, ",")
}
}

if langTmpl, ok = langTmpls[lang]; !ok {


+ 2
- 1
xorm/templates/go/config View File

@@ -1 +1,2 @@
lang=go
lang=go
ignoreColumnsJSON=