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

Conversation

gcjensen
Copy link

@gcjensen gcjensen commented Jan 15, 2024

I'm currently adding support to gen-dao for allowing the sort order used by the generated List function to be reversed. Whilst doing so, I noticed that the gocassa mocking doesn't currently respect the provided clustering order.

We've previously added mock support for clustering order at table creation (#82), but not as part of a query.

See https://github.com/monzo/wearedev/pull/172946 for the gen-dao change.

@gcjensen gcjensen force-pushed the query-clustering-order-in-mock branch from 3b9040a to a5e658c Compare January 15, 2024 14:11
@@ -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.)

@gcjensen gcjensen marked this pull request as ready for review January 15, 2024 15:11
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants