Add an order by query

This commit is contained in:
Aaron L 2016-07-31 21:05:03 -07:00
parent 4735ce993c
commit fd7cb01b89
4 changed files with 8 additions and 1 deletions

View file

@ -1 +1 @@
SELECT "count(*) as ab, thing as bd","stuff" FROM "t";
SELECT * FROM "q" ORDER BY a ASC,b DESC;

1
boil/_fixtures/03.sql Normal file
View file

@ -0,0 +1 @@
SELECT "count(*) as ab, thing as bd","stuff" FROM "t";

View file

@ -86,6 +86,11 @@ func buildSelectQuery(q *Query) (*bytes.Buffer, []interface{}) {
where, args := whereClause(q)
buf.WriteString(where)
if len(q.orderBy) != 0 {
buf.WriteString(" ORDER BY ")
buf.WriteString(strings.Join(q.orderBy, ","))
}
if q.limit != 0 {
fmt.Fprintf(buf, " LIMIT %d", q.limit)
}

View file

@ -28,6 +28,7 @@ func TestBuildQuery(t *testing.T) {
}{
{&Query{from: "t"}, nil},
{&Query{from: "q", limit: 5, offset: 6}, nil},
{&Query{from: "q", orderBy: []string{"a ASC", "b DESC"}}, nil},
{&Query{from: "t", selectCols: []string{"count(*) as ab, thing as bd", "stuff"}}, nil},
}