Commit 81c1bfd1 authored by Amos Wenger's avatar Amos Wenger

Add GroupBy

parent db807adf
Pipeline #12350 passed with stage
in 32 seconds
......@@ -13,12 +13,18 @@ type join struct {
}
type Search struct {
groups []string
orders []string
joins []join
offset *int64
limit *int64
}
func (s Search) GroupBy(group string) Search {
s.groups = append(s.groups, group)
return s
}
func (s Search) OrderBy(order string) Search {
s.orders = append(s.orders, order)
return s
......@@ -43,6 +49,10 @@ func (s Search) Join(joinTable string, joinCond string) Search {
}
func (s Search) Apply(sql string) string {
if len(s.groups) > 0 {
sql = fmt.Sprintf("%s GROUP BY %s", sql, strings.Join(s.groups, ", "))
}
if len(s.orders) > 0 {
sql = fmt.Sprintf("%s ORDER BY %s", sql, strings.Join(s.orders, ", "))
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment