-
Notifications
You must be signed in to change notification settings - Fork 0
Add ConvertOrderBy method for MongoDB-style sorting #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds MongoDB-style sorting support to the filter package by introducing a ConvertOrderBy
method that translates JSON sort objects to PostgreSQL ORDER BY clauses.
- Adds
ConvertOrderBy
method to convert MongoDB sort syntax ({"field": 1/-1}
) to PostgreSQL ORDER BY clauses - Implements dual sorting for JSONB fields to handle both numeric and text values properly
- Includes comprehensive integration tests and fuzz testing for the new functionality
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
File | Description |
---|---|
filter/converter.go | Implements the main ConvertOrderBy method with support for regular and JSONB fields |
filter/util.go | Adds objectInOrder helper function to parse JSON while preserving key order |
filter/errors.go | Defines InvalidOrderDirectionError for invalid sort direction values |
filter/converter_test.go | Unit tests covering various scenarios for the new ConvertOrderBy functionality |
integration/postgres_test.go | Integration tests verifying ORDER BY behavior with actual database queries |
fuzz/fuzz_test.go | Fuzz testing for ConvertOrderBy to catch edge cases and validate SQL generation |
README.md | Documents the new ORDER BY support with examples and usage patterns |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
427264c
to
9ae5a15
Compare
Add `ORDER BY` support with `ConvertOrderBy` method. - Converts MongoDB-style sort objects to PostgreSQL `ORDER BY` clauses. - Supports both regular columns and JSONB fields with dual sorting. - Includes integration tests and fuzz tests.
9ae5a15
to
58f4d34
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are doing some custom magic with json (for the key order), it might be smart to do some more unit tests with broken json input, trying to break the objectInOrder function.
@codex please review this pull request. |
Codex Review: Didn't find any major issues. Chef's kiss. About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback". |
Add
ORDER BY
support withConvertOrderBy
method.ORDER BY
clauses.