Skip to content

Commit

Permalink
order by fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sxwebdev committed Dec 19, 2023
1 parent 6d0436b commit 11ce516
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions select.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion tsdbbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 11ce516

Please sign in to comment.