From 11ce5160ebe855ad3dc7f5794b3e39da95f5ee91 Mon Sep 17 00:00:00 2001 From: sxwebdev Date: Wed, 20 Dec 2023 02:51:42 +0300 Subject: [PATCH] order by fixes --- select.go | 6 +++--- tsdbbuilder_test.go | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) 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 {