|
26 | 26 |
|
27 | 27 | func init() {
|
28 | 28 | GoXormTmp = `
|
29 |
| -{{- range .Tables}} |
| 29 | +{{- range .Tables -}} |
| 30 | +// SELECT: {{SelectRawSql .}} |
30 | 31 | type {{TableMapper .Name}} struct {
|
31 | 32 | {{$table := .}}
|
32 | 33 | {{range .ColumnsSeq}}{{$col := $table.GetColumn .}} {{ColMapper $col.Name}} {{Type $col}} {{Tag $table $col}}
|
@@ -186,14 +187,15 @@ func NewGolangTmp(args *convertArgs) *GolangTmp {
|
186 | 187 | }
|
187 | 188 | return &GolangTmp{
|
188 | 189 | funcs: template.FuncMap{
|
189 |
| - "ColMapper": colMapper.Table2Obj, |
190 |
| - "TableMapper": tableMapper.Table2Obj, |
191 |
| - "Type": typestring, |
192 |
| - "Tag": getTag(colMapper, args.genJson, args.genXorm, otherTags), |
193 |
| - "UnTitle": unTitle, |
194 |
| - "gt": gt, |
195 |
| - "getCol": getCol, |
196 |
| - "UpperTitle": upTitle, |
| 190 | + "ColMapper": colMapper.Table2Obj, |
| 191 | + "TableMapper": tableMapper.Table2Obj, |
| 192 | + "Type": typestring, |
| 193 | + "Tag": getTag(colMapper, args.genJson, args.genXorm, otherTags), |
| 194 | + "UnTitle": unTitle, |
| 195 | + "gt": gt, |
| 196 | + "getCol": getCol, |
| 197 | + "UpperTitle": upTitle, |
| 198 | + "SelectRawSql": GetSelectRawSql, |
197 | 199 | },
|
198 | 200 | formater: formatGo,
|
199 | 201 | args: args,
|
@@ -501,3 +503,12 @@ func include(source []string, target string) bool {
|
501 | 503 | }
|
502 | 504 | return false
|
503 | 505 | }
|
| 506 | + |
| 507 | +func GetSelectRawSql(table *schemas.Table) string { |
| 508 | + colNames := make([]string, 0, len(table.Columns())) |
| 509 | + for _, v := range table.ColumnsSeq() { |
| 510 | + col := table.GetColumn(v) |
| 511 | + colNames = append(colNames, "`"+col.Name+"`") |
| 512 | + } |
| 513 | + return fmt.Sprintf("SELECT %s FROM `%s`", strings.Join(colNames, ", "), table.Name) |
| 514 | +} |
0 commit comments