@@ -17,6 +17,50 @@ import (
17
17
"github.com/xormplus/core"
18
18
)
19
19
20
+ type Record map [string ]Value
21
+ type Result []Record
22
+
23
+ type ResultValue struct {
24
+ Result Result
25
+ Error error
26
+ }
27
+
28
+ func (resultValue * ResultValue ) List () (Result , error ) {
29
+ return resultValue .Result , resultValue .Error
30
+ }
31
+
32
+ func (resultValue * ResultValue ) Count () (int , error ) {
33
+ if resultValue .Error != nil {
34
+ return 0 , resultValue .Error
35
+ }
36
+ if resultValue .Result == nil {
37
+ return 0 , nil
38
+ }
39
+ return len (resultValue .Result ), nil
40
+ }
41
+
42
+ func (resultValue * ResultValue ) ListPage (firstResult int , maxResults int ) (Result , error ) {
43
+ if resultValue .Error != nil {
44
+ return nil , resultValue .Error
45
+ }
46
+ if resultValue .Result == nil {
47
+ return nil , nil
48
+ }
49
+ if firstResult > maxResults {
50
+ return nil , ErrParamsFormat
51
+ }
52
+ if firstResult < 0 {
53
+ return nil , ErrParamsFormat
54
+ }
55
+ if maxResults < 0 {
56
+ return nil , ErrParamsFormat
57
+ }
58
+ if maxResults > len (resultValue .Result ) {
59
+ return nil , ErrParamsFormat
60
+ }
61
+ return resultValue .Result [(firstResult - 1 ):maxResults ], resultValue .Error
62
+ }
63
+
20
64
type ResultBean struct {
21
65
Has bool
22
66
Result interface {}
@@ -102,29 +146,29 @@ func (resultBean *ResultBean) XmlIndent(prefix string, indent string, recordTag
102
146
}
103
147
104
148
type ResultMap struct {
105
- Results []map [string ]interface {}
106
- Error error
149
+ Result []map [string ]interface {}
150
+ Error error
107
151
}
108
152
109
153
func (resultMap * ResultMap ) List () ([]map [string ]interface {}, error ) {
110
- return resultMap .Results , resultMap .Error
154
+ return resultMap .Result , resultMap .Error
111
155
}
112
156
113
157
func (resultMap * ResultMap ) Count () (int , error ) {
114
158
if resultMap .Error != nil {
115
159
return 0 , resultMap .Error
116
160
}
117
- if resultMap .Results == nil {
161
+ if resultMap .Result == nil {
118
162
return 0 , nil
119
163
}
120
- return len (resultMap .Results ), nil
164
+ return len (resultMap .Result ), nil
121
165
}
122
166
123
167
func (resultMap * ResultMap ) ListPage (firstResult int , maxResults int ) ([]map [string ]interface {}, error ) {
124
168
if resultMap .Error != nil {
125
169
return nil , resultMap .Error
126
170
}
127
- if resultMap .Results == nil {
171
+ if resultMap .Result == nil {
128
172
return nil , nil
129
173
}
130
174
if firstResult > maxResults {
@@ -136,25 +180,25 @@ func (resultMap *ResultMap) ListPage(firstResult int, maxResults int) ([]map[str
136
180
if maxResults < 0 {
137
181
return nil , ErrParamsFormat
138
182
}
139
- if maxResults > len (resultMap .Results ) {
183
+ if maxResults > len (resultMap .Result ) {
140
184
return nil , ErrParamsFormat
141
185
}
142
- return resultMap .Results [(firstResult - 1 ):maxResults ], resultMap .Error
186
+ return resultMap .Result [(firstResult - 1 ):maxResults ], resultMap .Error
143
187
}
144
188
145
189
func (resultMap * ResultMap ) Json () (string , error ) {
146
190
147
191
if resultMap .Error != nil {
148
192
return "" , resultMap .Error
149
193
}
150
- return JSONString (resultMap .Results , true )
194
+ return JSONString (resultMap .Result , true )
151
195
}
152
196
153
197
func (resultMap * ResultMap ) Xml () (string , error ) {
154
198
if resultMap .Error != nil {
155
199
return "" , resultMap .Error
156
200
}
157
- results , err := anyxml .Xml (resultMap .Results )
201
+ results , err := anyxml .Xml (resultMap .Result )
158
202
if err != nil {
159
203
return "" , err
160
204
}
@@ -166,7 +210,7 @@ func (resultMap *ResultMap) XmlIndent(prefix string, indent string, recordTag st
166
210
return "" , resultMap .Error
167
211
}
168
212
169
- results , err := anyxml .XmlIndent (resultMap .Results , prefix , indent , recordTag )
213
+ results , err := anyxml .XmlIndent (resultMap .Result , prefix , indent , recordTag )
170
214
if err != nil {
171
215
return "" , err
172
216
}
@@ -178,7 +222,7 @@ func (resultMap *ResultMap) SaveAsCSV(filename string, headers []string, perm os
178
222
return resultMap .Error
179
223
}
180
224
181
- dataset , err := NewDatasetWithData (headers , resultMap .Results , true )
225
+ dataset , err := NewDatasetWithData (headers , resultMap .Result , true )
182
226
if err != nil {
183
227
return err
184
228
}
@@ -196,7 +240,7 @@ func (resultMap *ResultMap) SaveAsTSV(filename string, headers []string, perm os
196
240
return resultMap .Error
197
241
}
198
242
199
- dataset , err := NewDatasetWithData (headers , resultMap .Results , true )
243
+ dataset , err := NewDatasetWithData (headers , resultMap .Result , true )
200
244
if err != nil {
201
245
return err
202
246
}
@@ -214,7 +258,7 @@ func (resultMap *ResultMap) SaveAsHTML(filename string, headers []string, perm o
214
258
return resultMap .Error
215
259
}
216
260
217
- dataset , err := NewDatasetWithData (headers , resultMap .Results , true )
261
+ dataset , err := NewDatasetWithData (headers , resultMap .Result , true )
218
262
if err != nil {
219
263
return err
220
264
}
@@ -229,7 +273,7 @@ func (resultMap *ResultMap) SaveAsXML(filename string, headers []string, perm os
229
273
return resultMap .Error
230
274
}
231
275
232
- dataset , err := NewDatasetWithData (headers , resultMap .Results , false )
276
+ dataset , err := NewDatasetWithData (headers , resultMap .Result , false )
233
277
if err != nil {
234
278
return err
235
279
}
@@ -247,7 +291,7 @@ func (resultMap *ResultMap) SaveAsXMLWithTagNamePrefixIndent(tagName string, pri
247
291
return resultMap .Error
248
292
}
249
293
250
- dataset , err := NewDatasetWithData (headers , resultMap .Results , false )
294
+ dataset , err := NewDatasetWithData (headers , resultMap .Result , false )
251
295
if err != nil {
252
296
return err
253
297
}
@@ -265,7 +309,7 @@ func (resultMap *ResultMap) SaveAsYAML(filename string, headers []string, perm o
265
309
return resultMap .Error
266
310
}
267
311
268
- dataset , err := NewDatasetWithData (headers , resultMap .Results , false )
312
+ dataset , err := NewDatasetWithData (headers , resultMap .Result , false )
269
313
if err != nil {
270
314
return err
271
315
}
@@ -283,7 +327,7 @@ func (resultMap *ResultMap) SaveAsJSON(filename string, headers []string, perm o
283
327
return resultMap .Error
284
328
}
285
329
286
- dataset , err := NewDatasetWithData (headers , resultMap .Results , false )
330
+ dataset , err := NewDatasetWithData (headers , resultMap .Result , false )
287
331
if err != nil {
288
332
return err
289
333
}
@@ -301,7 +345,7 @@ func (resultMap *ResultMap) SaveAsXLSX(filename string, headers []string, perm o
301
345
return resultMap .Error
302
346
}
303
347
304
- dataset , err := NewDatasetWithData (headers , resultMap .Results , true )
348
+ dataset , err := NewDatasetWithData (headers , resultMap .Result , true )
305
349
if err != nil {
306
350
return err
307
351
}
@@ -504,7 +548,7 @@ func (session *Session) Query() *ResultMap {
504
548
}
505
549
}
506
550
}
507
- r := & ResultMap {Results : result , Error : err }
551
+ r := & ResultMap {Result : result , Error : err }
508
552
return r
509
553
}
510
554
@@ -548,7 +592,7 @@ func (session *Session) QueryWithDateFormat(dateFormat string) *ResultMap {
548
592
}
549
593
}
550
594
}
551
- r := & ResultMap {Results : result , Error : err }
595
+ r := & ResultMap {Result : result , Error : err }
552
596
return r
553
597
}
554
598
0 commit comments