forked from go-reform/reform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extra_reform.go
267 lines (227 loc) · 7.58 KB
/
extra_reform.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// Code generated by gopkg.in/reform.v1. DO NOT EDIT.
package models
import (
"fmt"
"strings"
"gopkg.in/reform.v1"
"gopkg.in/reform.v1/parse"
)
type extraTableType struct {
s parse.StructInfo
z []interface{}
}
// Schema returns a schema name in SQL database ("").
func (v *extraTableType) Schema() string {
return v.s.SQLSchema
}
// Name returns a view or table name in SQL database ("extra").
func (v *extraTableType) Name() string {
return v.s.SQLName
}
// Columns returns a new slice of column names for that view or table in SQL database.
func (v *extraTableType) Columns() []string {
return []string{"id", "name", "byte", "uint8", "bytep", "uint8p", "bytes", "uint8s", "bytesa", "uint8sa", "bytest", "uint8st"}
}
// NewStruct makes a new struct for that view or table.
func (v *extraTableType) NewStruct() reform.Struct {
return new(Extra)
}
// NewRecord makes a new record for that table.
func (v *extraTableType) NewRecord() reform.Record {
return new(Extra)
}
// PKColumnIndex returns an index of primary key column for that table in SQL database.
func (v *extraTableType) PKColumnIndex() uint {
return uint(v.s.PKFieldIndex)
}
// ExtraTable represents extra view or table in SQL database.
var ExtraTable = &extraTableType{
s: parse.StructInfo{Type: "Extra", SQLSchema: "", SQLName: "extra", Fields: []parse.FieldInfo{{Name: "ID", Type: "Integer", Column: "id"}, {Name: "Name", Type: "*String", Column: "name"}, {Name: "Byte", Type: "uint8", Column: "byte"}, {Name: "Uint8", Type: "uint8", Column: "uint8"}, {Name: "ByteP", Type: "*uint8", Column: "bytep"}, {Name: "Uint8P", Type: "*uint8", Column: "uint8p"}, {Name: "Bytes", Type: "[]uint8", Column: "bytes"}, {Name: "Uint8s", Type: "[]uint8", Column: "uint8s"}, {Name: "BytesA", Type: "[512]uint8", Column: "bytesa"}, {Name: "Uint8sA", Type: "[512]uint8", Column: "uint8sa"}, {Name: "BytesT", Type: "Bytes", Column: "bytest"}, {Name: "Uint8sT", Type: "Uint8s", Column: "uint8st"}}, PKFieldIndex: 0},
z: new(Extra).Values(),
}
// String returns a string representation of this struct or record.
func (s Extra) String() string {
res := make([]string, 12)
res[0] = "ID: " + reform.Inspect(s.ID, true)
res[1] = "Name: " + reform.Inspect(s.Name, true)
res[2] = "Byte: " + reform.Inspect(s.Byte, true)
res[3] = "Uint8: " + reform.Inspect(s.Uint8, true)
res[4] = "ByteP: " + reform.Inspect(s.ByteP, true)
res[5] = "Uint8P: " + reform.Inspect(s.Uint8P, true)
res[6] = "Bytes: " + reform.Inspect(s.Bytes, true)
res[7] = "Uint8s: " + reform.Inspect(s.Uint8s, true)
res[8] = "BytesA: " + reform.Inspect(s.BytesA, true)
res[9] = "Uint8sA: " + reform.Inspect(s.Uint8sA, true)
res[10] = "BytesT: " + reform.Inspect(s.BytesT, true)
res[11] = "Uint8sT: " + reform.Inspect(s.Uint8sT, true)
return strings.Join(res, ", ")
}
// Values returns a slice of struct or record field values.
// Returned interface{} values are never untyped nils.
func (s *Extra) Values() []interface{} {
return []interface{}{
s.ID,
s.Name,
s.Byte,
s.Uint8,
s.ByteP,
s.Uint8P,
s.Bytes,
s.Uint8s,
s.BytesA,
s.Uint8sA,
s.BytesT,
s.Uint8sT,
}
}
// Pointers returns a slice of pointers to struct or record fields.
// Returned interface{} values are never untyped nils.
func (s *Extra) Pointers() []interface{} {
return []interface{}{
&s.ID,
&s.Name,
&s.Byte,
&s.Uint8,
&s.ByteP,
&s.Uint8P,
&s.Bytes,
&s.Uint8s,
&s.BytesA,
&s.Uint8sA,
&s.BytesT,
&s.Uint8sT,
}
}
// View returns View object for that struct.
func (s *Extra) View() reform.View {
return ExtraTable
}
// Table returns Table object for that record.
func (s *Extra) Table() reform.Table {
return ExtraTable
}
// PKValue returns a value of primary key for that record.
// Returned interface{} value is never untyped nil.
func (s *Extra) PKValue() interface{} {
return s.ID
}
// PKPointer returns a pointer to primary key field for that record.
// Returned interface{} value is never untyped nil.
func (s *Extra) PKPointer() interface{} {
return &s.ID
}
// HasPK returns true if record has non-zero primary key set, false otherwise.
func (s *Extra) HasPK() bool {
return s.ID != ExtraTable.z[ExtraTable.s.PKFieldIndex]
}
// SetPK sets record primary key.
func (s *Extra) SetPK(pk interface{}) {
if i64, ok := pk.(int64); ok {
s.ID = Integer(i64)
} else {
s.ID = pk.(Integer)
}
}
// check interfaces
var (
_ reform.View = ExtraTable
_ reform.Struct = (*Extra)(nil)
_ reform.Table = ExtraTable
_ reform.Record = (*Extra)(nil)
_ fmt.Stringer = (*Extra)(nil)
)
type notExportedTableType struct {
s parse.StructInfo
z []interface{}
}
// Schema returns a schema name in SQL database ("").
func (v *notExportedTableType) Schema() string {
return v.s.SQLSchema
}
// Name returns a view or table name in SQL database ("not_exported").
func (v *notExportedTableType) Name() string {
return v.s.SQLName
}
// Columns returns a new slice of column names for that view or table in SQL database.
func (v *notExportedTableType) Columns() []string {
return []string{"id"}
}
// NewStruct makes a new struct for that view or table.
func (v *notExportedTableType) NewStruct() reform.Struct {
return new(notExported)
}
// NewRecord makes a new record for that table.
func (v *notExportedTableType) NewRecord() reform.Record {
return new(notExported)
}
// PKColumnIndex returns an index of primary key column for that table in SQL database.
func (v *notExportedTableType) PKColumnIndex() uint {
return uint(v.s.PKFieldIndex)
}
// notExportedTable represents not_exported view or table in SQL database.
var notExportedTable = ¬ExportedTableType{
s: parse.StructInfo{Type: "notExported", SQLSchema: "", SQLName: "not_exported", Fields: []parse.FieldInfo{{Name: "ID", Type: "string", Column: "id"}}, PKFieldIndex: 0},
z: new(notExported).Values(),
}
// String returns a string representation of this struct or record.
func (s notExported) String() string {
res := make([]string, 1)
res[0] = "ID: " + reform.Inspect(s.ID, true)
return strings.Join(res, ", ")
}
// Values returns a slice of struct or record field values.
// Returned interface{} values are never untyped nils.
func (s *notExported) Values() []interface{} {
return []interface{}{
s.ID,
}
}
// Pointers returns a slice of pointers to struct or record fields.
// Returned interface{} values are never untyped nils.
func (s *notExported) Pointers() []interface{} {
return []interface{}{
&s.ID,
}
}
// View returns View object for that struct.
func (s *notExported) View() reform.View {
return notExportedTable
}
// Table returns Table object for that record.
func (s *notExported) Table() reform.Table {
return notExportedTable
}
// PKValue returns a value of primary key for that record.
// Returned interface{} value is never untyped nil.
func (s *notExported) PKValue() interface{} {
return s.ID
}
// PKPointer returns a pointer to primary key field for that record.
// Returned interface{} value is never untyped nil.
func (s *notExported) PKPointer() interface{} {
return &s.ID
}
// HasPK returns true if record has non-zero primary key set, false otherwise.
func (s *notExported) HasPK() bool {
return s.ID != notExportedTable.z[notExportedTable.s.PKFieldIndex]
}
// SetPK sets record primary key.
func (s *notExported) SetPK(pk interface{}) {
if i64, ok := pk.(int64); ok {
s.ID = string(i64)
} else {
s.ID = pk.(string)
}
}
// check interfaces
var (
_ reform.View = notExportedTable
_ reform.Struct = (*notExported)(nil)
_ reform.Table = notExportedTable
_ reform.Record = (*notExported)(nil)
_ fmt.Stringer = (*notExported)(nil)
)
func init() {
parse.AssertUpToDate(&ExtraTable.s, new(Extra))
parse.AssertUpToDate(¬ExportedTable.s, new(notExported))
}