@@ -6,9 +6,11 @@ import (
66 "strings"
77 "text/template"
88 "unicode"
9+
10+ "github.com/muxi-Infra/muxi-micro/tool/curd/parse"
911)
1012
11- func CreateVar (pkg , dir string , open , cover bool ) error {
13+ func CreateVar (pkg , table , dir string , open , cover bool ) error {
1214 if cover == false && ! CheckExist (dir , "var.go" ) {
1315 return nil
1416 }
@@ -34,8 +36,10 @@ func CreateVar(pkg, dir string, open, cover bool) error {
3436
3537 data := struct {
3638 PackageName string
39+ ModelName string
3740 }{
3841 PackageName : pkg ,
42+ ModelName : table ,
3943 }
4044
4145 if err := t .ExecuteTemplate (file , "var" , data ); err != nil {
@@ -84,7 +88,7 @@ func CreateExample(pkg, dir, table string, open, cover bool) error {
8488 return nil
8589}
8690
87- func CreateExample_gen (pkg , dir , table string , fields []string , open bool ) error {
91+ func CreateExample_gen (pkg , dir , table string , fields []parse. FieldInfo , open bool ) error {
8892 var tmplPath []string
8993 if open {
9094 tmplPath = []string {
@@ -115,15 +119,15 @@ func CreateExample_gen(pkg, dir, table string, fields []string, open bool) error
115119 data := struct {
116120 PackageName string
117121 ModelName string
118- Fields []string
119- NotPrs []string
122+ Fields []parse. FieldInfo
123+ NotPrs []parse. FieldInfo
120124 Pr string
121125 }{
122126 PackageName : pkg ,
123127 ModelName : table ,
124128 Fields : fields ,
125129 NotPrs : fields [:len (fields )- 1 ],
126- Pr : fields [len (fields )- 1 ],
130+ Pr : fields [len (fields )- 1 ]. Name ,
127131 }
128132
129133 if err := t .ExecuteTemplate (file , "header" , data ); err != nil {
@@ -133,6 +137,38 @@ func CreateExample_gen(pkg, dir, table string, fields []string, open bool) error
133137 return nil
134138}
135139
140+ func CreateTranscation (pkg , dir string , transcation bool ) error {
141+ if transcation == false {
142+ return nil
143+ }
144+ var tmplPath string
145+ tmplPath = filepath .Join ("curd" , "template" , "transaction.tpl" )
146+ t , err := template .New ("header" ).ParseFiles (tmplPath )
147+ if err != nil {
148+ return err
149+ }
150+
151+ outputPath := filepath .Join (dir , "transaction.go" )
152+ file , err := os .Create (outputPath )
153+ if err != nil {
154+ return err
155+ }
156+
157+ defer file .Close ()
158+
159+ data := struct {
160+ PackageName string
161+ }{
162+ PackageName : pkg ,
163+ }
164+
165+ if err := t .ExecuteTemplate (file , "transaction" , data ); err != nil {
166+ return err
167+ }
168+
169+ return nil
170+ }
171+
136172func safeFilename (tableName string ) string {
137173 return strings .Map (func (r rune ) rune {
138174 if unicode .IsLetter (r ) || unicode .IsDigit (r ) || r == '_' || r == '-' {
0 commit comments