Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Add support for query-level DESC clustering order in the mock #90

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,13 @@ func (q *MockFilter) Read(out interface{}) Op {
return err
}

// If a query-level clustering order has been provided, and the first one is descending, reverse the list
if len(m.options.ClusteringOrder) > 0 && m.options.ClusteringOrder[0].Direction == DESC {
for i, j := 0, len(result)-1; i < j; i, j = i+1, j-1 {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could bump the version of Go so that slices.Reverse is available, but I was worried that might have some knock on effects and make this a bigger change (due to dependencies and the CI etc. etc.)

result[i], result[j] = result[j], result[i]
}
}

opt := q.table.options.Merge(m.options)
if opt.Limit > 0 && opt.Limit < len(result) {
result = result[:opt.Limit]
Expand Down
8 changes: 8 additions & 0 deletions mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,14 @@ func (s *MockSuite) TestMultiMapTableList() {
s.NoError(s.mmapTbl.List(1, 2, 1, &users).Run())
s.Len(users, 1)
s.Equal("Joe", users[0].Name)

// Order DESC
s.NoError(s.mmapTbl.List(1, 0, 10, &users).WithOptions(Options{
ClusteringOrder: []ClusteringOrderColumn{{Column: "Name", Direction: DESC}},
}).Run())
s.Len(users, 2)
s.Equal("Joe", users[0].Name)
s.Equal("Jane", users[1].Name)
}

func (s *MockSuite) TestMultiMapTableUpdate() {
Expand Down