Add an order by query
This commit is contained in:
parent
4735ce993c
commit
fd7cb01b89
4 changed files with 8 additions and 1 deletions
|
@ -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
1
boil/_fixtures/03.sql
Normal file
|
@ -0,0 +1 @@
|
|||
SELECT "count(*) as ab, thing as bd","stuff" FROM "t";
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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},
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue