File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ type QueryStatement struct {
39
39
hasRowcount bool
40
40
rowcount int
41
41
useRowcount bool
42
+ hasGroupBy bool
43
+ groupBy string
42
44
}
43
45
44
46
// NewQueryStatement returns a new instance of the select statement
@@ -110,6 +112,15 @@ func (q *QueryStatement) Where(where string) *QueryStatement {
110
112
return q
111
113
}
112
114
115
+ // GroupBy will append a group by statement to the query
116
+ func (q * QueryStatement ) GroupBy (groupBy string ) * QueryStatement {
117
+ if len (groupBy ) > 0 {
118
+ q .groupBy = groupBy
119
+ q .hasGroupBy = true
120
+ }
121
+ return q
122
+ }
123
+
113
124
// And continues to add to the where statement
114
125
func (q * QueryStatement ) And (param string ) * QueryStatement {
115
126
if len (param ) > 0 {
@@ -241,6 +252,11 @@ func (q *QueryStatement) Assemble() (string, error) {
241
252
}
242
253
}
243
254
255
+ if q .hasGroupBy {
256
+ sql .WriteString (" GROUP BY " )
257
+ sql .WriteString (q .groupBy )
258
+ }
259
+
244
260
if q .hasOrderBy {
245
261
sql .WriteString (" ORDER BY " )
246
262
sql .WriteString (q .orderby )
You can’t perform that action at this time.
0 commit comments