Skip to content

Conversation

erikdubbelboer
Copy link
Member

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.

Copy link

@Copilot Copilot AI left a 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.

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.
Copy link
Collaborator

@koenbollen koenbollen left a 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.

@erikdubbelboer
Copy link
Member Author

@codex please review this pull request.

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Chef's kiss.

About Codex in GitHub

Your 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".

@erikdubbelboer erikdubbelboer marked this pull request as ready for review September 19, 2025 20:54
@erikdubbelboer erikdubbelboer merged commit 3bbfed9 into main Sep 22, 2025
9 checks passed
@erikdubbelboer erikdubbelboer deleted the order-by branch September 22, 2025 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants