Skip to content

Commit 11ce516

Browse files
committed
order by fixes
1 parent 6d0436b commit 11ce516

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

select.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,17 @@ func (s *selectBuilder) Build() (string, error) {
101101

102102
// add group by
103103
if s.groupBy != "" {
104-
b.WriteString(s.groupBy + " ")
104+
b.WriteString(" GROUP BY " + s.groupBy + " ")
105105
}
106106

107107
// add partition by
108108
if s.partitionBy != "" {
109-
b.WriteString(s.partitionBy + " ")
109+
b.WriteString(" PARTITION BY " + s.partitionBy + " ")
110110
}
111111

112112
// add order by
113113
if s.orderBy != "" {
114-
b.WriteString(s.orderBy + " ")
114+
b.WriteString(" ORDER BY " + s.orderBy + " ")
115115
}
116116

117117
// add limit

tsdbbuilder_test.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,19 @@ func Test_Delete(t *testing.T) {
8383
}
8484

8585
func Test_Select(t *testing.T) {
86+
limit := uint64(10)
87+
offset := uint64(0)
88+
8689
b := tsbuilder.NewSelectBuilder().
8790
Columns("col_1", "col_2", "col_3").
8891
From("dbName.test_table").
8992
Where(
9093
"asasd > asd",
9194
"asdfasdf <= 1212",
92-
)
95+
).
96+
OrderBy("ts desc").
97+
Limit(&limit).
98+
Offset(&offset)
9399

94100
sql, err := b.Build()
95101
if err != nil {

0 commit comments

Comments
 (0)