Skip to content
This repository was archived by the owner on Jun 6, 2019. It is now read-only.

Commit 8bca8e8

Browse files
committed
add comment tag when database support
1 parent f31e54e commit 8bca8e8

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

xorm/go.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import (
1717
)
1818

1919
var (
20-
GoLangTmpl LangTmpl = LangTmpl{
20+
supportComment bool
21+
GoLangTmpl LangTmpl = LangTmpl{
2122
template.FuncMap{"Mapper": mapper.Table2Obj,
2223
"Type": typestring,
2324
"Tag": tag,
@@ -223,6 +224,9 @@ func tag(table *core.Table, col *core.Column) string {
223224
if col.IsUpdated {
224225
res = append(res, "updated")
225226
}
227+
if supportComment && col.Comment != "" {
228+
res = append(res, fmt.Sprintf("comment('%s')", col.Comment))
229+
}
226230

227231
names := make([]string, 0, len(col.Indexes))
228232
for name := range col.Indexes {

xorm/reverse.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ according database's tables and columns to generate codes for Go, C++ and etc.
3636
driverName Database driver name, now supported four: mysql mymysql sqlite3 postgres
3737
datasourceName Database connection uri, for detail infomation please visit driver's project page
3838
tmplPath Template dir for generated. the default templates dir has provide 1 template
39-
generatedPath This parameter is optional, if blank, the default value is model, then will
40-
generated all codes in model dir
39+
generatedPath This parameter is optional, if blank, the default value is models, then will
40+
generated all codes in models dir
4141
tableFilterReg Table name filter regexp
4242
`,
4343
}
@@ -60,7 +60,7 @@ func printReversePrompt(flag string) {
6060
type Tmpl struct {
6161
Tables []*core.Table
6262
Imports map[string]string
63-
Model string
63+
Models string
6464
}
6565

6666
func dirExists(dir string) bool {
@@ -120,7 +120,7 @@ func runReverse(cmd *Command, args []string) {
120120
}
121121
}
122122
} else {
123-
model = "model"
123+
model = "models"
124124
genDir = path.Join(curPath, model)
125125
}
126126

@@ -165,6 +165,8 @@ func runReverse(cmd *Command, args []string) {
165165

166166
os.MkdirAll(genDir, os.ModePerm)
167167

168+
supportComment = (args[0] == "mysql" || args[0] == "mymysql")
169+
168170
Orm, err := xorm.NewEngine(args[0], args[1])
169171
if err != nil {
170172
log.Errorf("%v", err)
@@ -236,7 +238,7 @@ func runReverse(cmd *Command, args []string) {
236238

237239
newbytes := bytes.NewBufferString("")
238240

239-
t := &Tmpl{Tables: tbls, Imports: imports, Model: model}
241+
t := &Tmpl{Tables: tbls, Imports: imports, Models: model}
240242
err = tmpl.Execute(newbytes, t)
241243
if err != nil {
242244
log.Errorf("%v", err)
@@ -271,15 +273,16 @@ func runReverse(cmd *Command, args []string) {
271273
tbs := []*core.Table{table}
272274
imports := langTmpl.GenImports(tbs)
273275

274-
w, err := os.Create(path.Join(genDir, unTitle(mapper.Table2Obj(table.Name))+ext))
276+
w, err := os.Create(path.Join(genDir, table.Name+ext))
275277
if err != nil {
276278
log.Errorf("%v", err)
277279
return err
278280
}
281+
defer w.Close()
279282

280283
newbytes := bytes.NewBufferString("")
281284

282-
t := &Tmpl{Tables: tbs, Imports: imports, Model: model}
285+
t := &Tmpl{Tables: tbs, Imports: imports, Models: model}
283286
err = tmpl.Execute(newbytes, t)
284287
if err != nil {
285288
log.Errorf("%v", err)

xorm/templates/go/struct.go.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package {{.Model}}
1+
package {{.Models}}
22

33
import (
44
{{range .Imports}}"{{.}}"{{end}}

xorm/templates/gomeddler/struct.go.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package {{.Model}}
1+
package {{.Models}}
22

33
{{$ilen := len .Imports}}
44
{{if gt $ilen 0}}

xorm/templates/goxorm/struct.go.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package {{.Model}}
1+
package {{.Models}}
22

33
{{$ilen := len .Imports}}
44
{{if gt $ilen 0}}

xorm/xorm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
2222
const go11tag = true
2323

24-
const version = "0.2.0524"
24+
const version = "0.3.0324"
2525

2626
var supportedDrivers = map[string]string{
2727
"mysql": "github.com/go-sql-driver/mysql",

0 commit comments

Comments
 (0)