diff options
author | 2023-06-19 14:00:10 -0700 | |
---|---|---|
committer | 2023-06-19 14:13:19 -0700 | |
commit | 28775f5e10b1b00e717abd06f369c45eae2bdea1 (patch) | |
tree | feb777b58c1f30899aed0f3eaab2951d0ea3593a /storage/feed_query_builder.go | |
parent | 095bec072c944ceafc1e09221c5c37ebe17eccb5 (diff) | |
download | v2-28775f5e10b1b00e717abd06f369c45eae2bdea1.tar.gz v2-28775f5e10b1b00e717abd06f369c45eae2bdea1.tar.zst v2-28775f5e10b1b00e717abd06f369c45eae2bdea1.zip |
Refactor entry/feed query builder sorting to match SQL semantic
Diffstat (limited to 'storage/feed_query_builder.go')
-rw-r--r-- | storage/feed_query_builder.go | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/storage/feed_query_builder.go b/storage/feed_query_builder.go index 1c310eb7..8ef2d9a7 100644 --- a/storage/feed_query_builder.go +++ b/storage/feed_query_builder.go @@ -18,8 +18,7 @@ type FeedQueryBuilder struct { store *Storage args []interface{} conditions []string - order string - direction string + sortExpressions []string limit int offset int withCounters bool @@ -66,15 +65,9 @@ func (f *FeedQueryBuilder) WithCounters() *FeedQueryBuilder { return f } -// WithOrder set the sorting order. -func (f *FeedQueryBuilder) WithOrder(order string) *FeedQueryBuilder { - f.order = order - return f -} - -// WithDirection set the sorting direction. -func (f *FeedQueryBuilder) WithDirection(direction string) *FeedQueryBuilder { - f.direction = direction +// WithSorting add a sort expression. +func (f *FeedQueryBuilder) WithSorting(column, direction string) *FeedQueryBuilder { + f.sortExpressions = append(f.sortExpressions, fmt.Sprintf("%s %s", column, direction)) return f } @@ -101,12 +94,8 @@ func (f *FeedQueryBuilder) buildCounterCondition() string { func (f *FeedQueryBuilder) buildSorting() string { var parts []string - if f.order != "" { - parts = append(parts, fmt.Sprintf(`ORDER BY %s`, f.order)) - } - - if f.direction != "" { - parts = append(parts, f.direction) + if len(f.sortExpressions) > 0 { + parts = append(parts, fmt.Sprintf(`ORDER BY %s`, strings.Join(f.sortExpressions, ", "))) } if len(parts) > 0 { |