forked from go-xorm/xorm
/
c++.go
65 lines (60 loc) · 1.66 KB
/
c++.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
//"fmt"
"github.com/lunny/xorm"
"strings"
"text/template"
)
var (
CPlusTmpl LangTmpl = LangTmpl{
template.FuncMap{"Mapper": mapper.Table2Obj,
"Type": cPlusTypeStr,
"UnTitle": unTitle,
},
nil,
genCPlusImports,
}
)
func cPlusTypeStr(col *xorm.Column) string {
tp := col.SQLType
name := strings.ToUpper(tp.Name)
switch name {
case xorm.Bit, xorm.TinyInt, xorm.SmallInt, xorm.MediumInt, xorm.Int, xorm.Integer, xorm.Serial:
return "int"
case xorm.BigInt, xorm.BigSerial:
return "__int64"
case xorm.Char, xorm.Varchar, xorm.TinyText, xorm.Text, xorm.MediumText, xorm.LongText:
return "tstring"
case xorm.Date, xorm.DateTime, xorm.Time, xorm.TimeStamp:
return "time_t"
case xorm.Decimal, xorm.Numeric:
return "tstring"
case xorm.Real, xorm.Float:
return "float"
case xorm.Double:
return "double"
case xorm.TinyBlob, xorm.Blob, xorm.MediumBlob, xorm.LongBlob, xorm.Bytea:
return "tstring"
case xorm.Bool:
return "bool"
default:
return "tstring"
}
return ""
}
func genCPlusImports(tables []*xorm.Table) map[string]string {
imports := make(map[string]string)
for _, table := range tables {
for _, col := range table.Columns {
switch cPlusTypeStr(col) {
case "time_t":
imports[`<time.h>`] = `<time.h>`
case "tstring":
imports["<string>"] = "<string>"
//case "__int64":
// imports[""] = ""
}
}
}
return imports
}