diff --git a/select.go b/select.go index 4bed96d..62c4061 100644 --- a/select.go +++ b/select.go @@ -101,17 +101,17 @@ func (s *selectBuilder) Build() (string, error) { // add group by if s.groupBy != "" { - b.WriteString(s.groupBy + " ") + b.WriteString(" GROUP BY " + s.groupBy + " ") } // add partition by if s.partitionBy != "" { - b.WriteString(s.partitionBy + " ") + b.WriteString(" PARTITION BY " + s.partitionBy + " ") } // add order by if s.orderBy != "" { - b.WriteString(s.orderBy + " ") + b.WriteString(" ORDER BY " + s.orderBy + " ") } // add limit diff --git a/tsdbbuilder_test.go b/tsdbbuilder_test.go index 5d74166..e8491a8 100644 --- a/tsdbbuilder_test.go +++ b/tsdbbuilder_test.go @@ -83,13 +83,19 @@ func Test_Delete(t *testing.T) { } func Test_Select(t *testing.T) { + limit := uint64(10) + offset := uint64(0) + b := tsbuilder.NewSelectBuilder(). Columns("col_1", "col_2", "col_3"). From("dbName.test_table"). Where( "asasd > asd", "asdfasdf <= 1212", - ) + ). + OrderBy("ts desc"). + Limit(&limit). + Offset(&offset) sql, err := b.Build() if err != nil {