forked from xo/xo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
171 lines (151 loc) · 3.11 KB
/
types.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package internal
import "github.com/knq/xo/models"
// TemplateType represents a template type.
type TemplateType uint
// the order here will be the alter the output order per file.
const (
EnumTemplate TemplateType = iota
ProcTemplate
TypeTemplate
ForeignKeyTemplate
IndexTemplate
QueryTypeTemplate
QueryTemplate
// always last
XOTemplate
)
// String returns the name for the associated template type.
func (tt TemplateType) String() string {
var s string
switch tt {
case XOTemplate:
s = "xo_db"
case EnumTemplate:
s = "enum"
case ProcTemplate:
s = "proc"
case TypeTemplate:
s = "type"
case ForeignKeyTemplate:
s = "foreignkey"
case IndexTemplate:
s = "index"
case QueryTypeTemplate:
s = "querytype"
case QueryTemplate:
s = "query"
default:
panic("unknown TemplateType")
}
return s
}
// RelType represents the different types of relational storage (table/view).
type RelType uint
const (
// Table reltype
Table RelType = iota
// View reltype
View
)
// EscType represents the different escape types.
type EscType uint
const (
SchemaEsc = iota
TableEsc
ColumnEsc
)
// String provides the string representation of RelType.
func (rt RelType) String() string {
var s string
switch rt {
case Table:
s = "TABLE"
case View:
s = "VIEW"
default:
panic("unknown RelType")
}
return s
}
// EnumValue holds data for a single enum value.
type EnumValue struct {
Name string
Val *models.EnumValue
Comment string
}
// Enum is a template item for a enum.
type Enum struct {
Name string
Schema string
Values []*EnumValue
Enum *models.Enum
Comment string
ReverseConstNames bool
}
// Proc is a template item for a stored procedure.
type Proc struct {
Name string
Schema string
ProcParams string
Params []*Field
Return *Field
Proc *models.Proc
Comment string
}
// Field contains field information.
type Field struct {
Name string
Type string
NilType string
Len int
Col *models.Column
Comment string
}
// Type is a template item for a type (ie, table/view/custom query).
type Type struct {
Name string
Schema string
RelType RelType
PrimaryKey *Field
Fields []*Field
Table *models.Table
Comment string
}
// ForeignKey is a template item for a foreign relationship on a table.
type ForeignKey struct {
Name string
Schema string
Type *Type
Field *Field
RefType *Type
RefField *Field
ForeignKey *models.ForeignKey
Comment string
}
// Index is a template item for a index into a table.
type Index struct {
FuncName string
Schema string
Type *Type
Fields []*Field
Index *models.Index
Comment string
}
// QueryParam is a query parameter for a custom query.
type QueryParam struct {
Name string
Type string
Interpolate bool
}
// Query is a template item for a custom query.
type Query struct {
Schema string
Name string
Query []string
QueryComments []string
QueryParams []*QueryParam
OnlyOne bool
Interpolate bool
Type *Type
Comment string
}