GroupBy and Having work now
This commit is contained in:
parent
d999c7b4d7
commit
f6d113a5ef
3 changed files with 14 additions and 0 deletions
1
boil/_fixtures/07.sql
Normal file
1
boil/_fixtures/07.sql
Normal file
|
@ -0,0 +1 @@
|
|||
SELECT * FROM "a" GROUP BY id,name HAVING id <> 1,length(name, 'utf8') > 5;
|
|
@ -73,6 +73,14 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) {
|
|||
where, args := whereClause(q)
|
||||
buf.WriteString(where)
|
||||
|
||||
if len(q.groupBy) != 0 {
|
||||
fmt.Fprintf(buf, " GROUP BY %s", strings.Join(q.groupBy, ","))
|
||||
}
|
||||
|
||||
if len(q.having) != 0 {
|
||||
fmt.Fprintf(buf, " HAVING %s", strings.Join(q.having, ","))
|
||||
}
|
||||
|
||||
if len(q.orderBy) != 0 {
|
||||
buf.WriteString(" ORDER BY ")
|
||||
buf.WriteString(strings.Join(q.orderBy, `,`))
|
||||
|
|
|
@ -39,6 +39,11 @@ func TestBuildQuery(t *testing.T) {
|
|||
from: []string{"happiness as a"},
|
||||
joins: []join{{clause: "rainbows r on a.id = r.happy_id"}},
|
||||
}, nil},
|
||||
{&Query{
|
||||
from: []string{"a"},
|
||||
groupBy: []string{"id", "name"},
|
||||
having: []string{"id <> 1", "length(name, 'utf8') > 5"},
|
||||
}, nil},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
|
|
Loading…
Add table
Reference in a new issue