added genJson for xorm tool
This commit is contained in:
parent
1d0ca7b116
commit
1031aa7b45
5
mysql.go
5
mysql.go
|
@ -216,6 +216,11 @@ func (db *mysql) GetColumns(tableName string) (map[string]*Column, error) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if col.SQLType.IsText() {
|
||||
if col.Default != "" {
|
||||
col.Default = "'" + col.Default + "'"
|
||||
}
|
||||
}
|
||||
cols[col.Name] = col
|
||||
}
|
||||
return cols, nil
|
||||
|
|
|
@ -165,6 +165,8 @@ func (db *postgres) GetColumns(tableName string) (map[string]*Column, error) {
|
|||
case "column_default":
|
||||
if strings.HasPrefix(string(content), "nextval") {
|
||||
col.IsPrimaryKey = true
|
||||
} else {
|
||||
col.Default = string(content)
|
||||
}
|
||||
case "is_nullable":
|
||||
if string(content) == "YES" {
|
||||
|
@ -201,6 +203,11 @@ func (db *postgres) GetColumns(tableName string) (map[string]*Column, error) {
|
|||
case "numeric_precision_radix":
|
||||
}
|
||||
}
|
||||
if col.SQLType.IsText() {
|
||||
if col.Default != "" {
|
||||
col.Default = "'" + col.Default + "'"
|
||||
}
|
||||
}
|
||||
cols[col.Name] = col
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,11 @@ example:
|
|||
|
||||
`xorm reverse sqite3 test.db templates/goxorm`
|
||||
|
||||
will generated go files in `./model` directory
|
||||
will generated go files in `./model` directory
|
||||
|
||||
## Template and Config
|
||||
|
||||
Now, xorm tool supports go and c++ two languages and have go, goxorm, c++ three of default templates. In
|
||||
|
||||
## LICENSE
|
||||
|
||||
|
|
14
xorm/go.go
14
xorm/go.go
|
@ -94,8 +94,16 @@ func tag(table *xorm.Table, col *xorm.Column) string {
|
|||
res = append(res, uistr)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return "`xorm:\"" + strings.Join(res, " ") + "\"`"
|
||||
var tags []string
|
||||
if genJson {
|
||||
tags = append(tags, "json:\""+col.Name+"\"")
|
||||
}
|
||||
if len(res) > 0 {
|
||||
tags = append(tags, "xorm:\""+strings.Join(res, " ")+"\"")
|
||||
}
|
||||
if len(tags) > 0 {
|
||||
return "`" + strings.Join(tags, " ") + "`"
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"text/template"
|
||||
)
|
||||
|
||||
|
@ -39,6 +40,10 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
var (
|
||||
genJson bool = false
|
||||
)
|
||||
|
||||
func printReversePrompt(flag string) {
|
||||
}
|
||||
|
||||
|
@ -100,7 +105,12 @@ func runReverse(cmd *Command, args []string) {
|
|||
var configs map[string]string
|
||||
if err == nil && !info.IsDir() {
|
||||
configs = loadConfig(cfgPath)
|
||||
lang = configs["lang"]
|
||||
if l, ok := configs["lang"]; ok {
|
||||
lang = l
|
||||
}
|
||||
if j, ok := configs["genJson"]; ok {
|
||||
genJson, err = strconv.ParseBool(j)
|
||||
}
|
||||
}
|
||||
|
||||
if langTmpl, ok = langTmpls[lang]; !ok {
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
lang=go
|
||||
lang=go
|
||||
genJson=0
|
||||
|
|
Loading…
Reference in New Issue