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
|
cols[col.Name] = col
|
||||||
}
|
}
|
||||||
return cols, nil
|
return cols, nil
|
||||||
|
|
|
@ -165,6 +165,8 @@ func (db *postgres) GetColumns(tableName string) (map[string]*Column, error) {
|
||||||
case "column_default":
|
case "column_default":
|
||||||
if strings.HasPrefix(string(content), "nextval") {
|
if strings.HasPrefix(string(content), "nextval") {
|
||||||
col.IsPrimaryKey = true
|
col.IsPrimaryKey = true
|
||||||
|
} else {
|
||||||
|
col.Default = string(content)
|
||||||
}
|
}
|
||||||
case "is_nullable":
|
case "is_nullable":
|
||||||
if string(content) == "YES" {
|
if string(content) == "YES" {
|
||||||
|
@ -201,6 +203,11 @@ func (db *postgres) GetColumns(tableName string) (map[string]*Column, error) {
|
||||||
case "numeric_precision_radix":
|
case "numeric_precision_radix":
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if col.SQLType.IsText() {
|
||||||
|
if col.Default != "" {
|
||||||
|
col.Default = "'" + col.Default + "'"
|
||||||
|
}
|
||||||
|
}
|
||||||
cols[col.Name] = col
|
cols[col.Name] = col
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,10 @@ example:
|
||||||
|
|
||||||
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
|
## LICENSE
|
||||||
|
|
||||||
BSD License
|
BSD License
|
||||||
|
|
12
xorm/go.go
12
xorm/go.go
|
@ -94,8 +94,16 @@ func tag(table *xorm.Table, col *xorm.Column) string {
|
||||||
res = append(res, uistr)
|
res = append(res, uistr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(res) > 0 {
|
var tags []string
|
||||||
return "`xorm:\"" + strings.Join(res, " ") + "\"`"
|
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"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"text/template"
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -39,6 +40,10 @@ func init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
genJson bool = false
|
||||||
|
)
|
||||||
|
|
||||||
func printReversePrompt(flag string) {
|
func printReversePrompt(flag string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +105,12 @@ func runReverse(cmd *Command, args []string) {
|
||||||
var configs map[string]string
|
var configs map[string]string
|
||||||
if err == nil && !info.IsDir() {
|
if err == nil && !info.IsDir() {
|
||||||
configs = loadConfig(cfgPath)
|
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 {
|
if langTmpl, ok = langTmpls[lang]; !ok {
|
||||||
|
|
|
@ -1 +1,2 @@
|
||||||
lang=go
|
lang=go
|
||||||
|
genJson=0
|
||||||
|
|
Loading…
Reference in New Issue