You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add ConvertOrderBy method for MongoDB-style sorting
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.
(given "customdata" is configured with `filter.WithNestedJSONB("customdata", "password", "playerCount")`)
98
98
99
99
100
+
## Order By Support
101
+
102
+
In addition to filtering, this package also supports converting MongoDB-style sort objects into PostgreSQL ORDER BY clauses using the `ConvertOrderBy` method:
// Generates: (CASE WHEN jsonb_typeof(metadata->'score') = 'number' THEN (metadata->>'score')::numeric END) DESC NULLS LAST, metadata->>'score' DESC NULLS LAST
128
+
```
129
+
130
+
This ensures proper sorting whether the JSONB field contains numeric or text values.
131
+
132
+
100
133
## Difference with MongoDB
101
134
102
135
- The MongoDB query filters don't have the option to compare fields with each other. This package adds the `$field` operator to compare fields with each other.
`(CASE WHEN jsonb_typeof(customdata->'map') = 'number' THEN ("customdata"->>'map')::numeric END) DESC NULLS LAST, "customdata"->>'map' DESC NULLS LAST`,
`(CASE WHEN jsonb_typeof(customdata->'map') = 'number' THEN ("customdata"->>'map')::numeric END) ASC NULLS LAST, "customdata"->>'map' ASC NULLS LAST, (CASE WHEN jsonb_typeof(customdata->'bar') = 'number' THEN ("customdata"->>'bar')::numeric END) DESC NULLS LAST, "customdata"->>'bar' DESC NULLS LAST`,
0 commit comments