-
Notifications
You must be signed in to change notification settings - Fork 334
Introduce query builder DSL #4812
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
blackheaven
left a comment
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.
I'd prefer using dedicated eDSLs such as esqueleto, but it least it simplifies things.
| } | ||
|
|
||
| -- | Construct a WHERE clause from a list of fragments. | ||
| where_ :: [QueryFragment] -> QueryFragment |
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.
If frags is empty this might produce an invalid query, no? Of course, it's the callers' responsibility, but this would be an easy safeguard, IMO.
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.
Sure, but this is not meant to produce only valid queries. You can also write nonsense in literal fragments. So I don't really see the point in adding these checks.
| clause1 :: forall a. (PostgresValue a) => Text -> Text -> a -> QueryFragment | ||
| clause1 field op value = clause op (mkClause field value) | ||
|
|
||
| orderBy :: [(Text, SortOrder)] -> QueryFragment |
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.
Same problem as above with where_.
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 introduces a query builder DSL for constructing dynamic PostgreSQL queries to support channel search functionality. The DSL provides a composable way to build SQL statements with proper parameter encoding and reduces code duplication in database query construction.
- Introduces a new
Wire.Postgresmodule with a query builder DSL for constructing PostgreSQL statements - Refactors the user group search functionality to use the new DSL instead of manual query construction
- Generalizes pagination state handling to support different entity types
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
libs/wire-subsystems/src/Wire/Postgres.hs |
New module implementing the query builder DSL with fragment composition and parameter encoding |
libs/wire-subsystems/src/Wire/PaginationState.hs |
Generalized pagination state type to work with different ID types |
libs/wire-subsystems/src/Wire/UserGroupSubsystem.hs |
Replaces multiple individual parameters with a GroupSearch data structure |
libs/wire-subsystems/src/Wire/UserGroupSubsystem/Interpreter.hs |
Updates to use the new GroupSearch structure and pagination state |
libs/wire-subsystems/src/Wire/UserGroupStore/Postgres.hs |
Refactored to use the query builder DSL instead of manual SQL construction |
libs/wire-subsystems/src/Wire/UserGroupStore.hs |
Updates pagination state type to be generic and changes time handling |
services/brig/src/Brig/API/Public.hs |
Updates API layer to construct GroupSearch structure |
libs/wire-subsystems/test/unit/Wire/UserGroupSubsystem/InterpreterSpec.hs |
Test updates to use new GroupSearch structure with def |
libs/wire-subsystems/test/unit/Wire/MockInterpreters/UserGroupStore.hs |
Mock implementation updates for type conversion functions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| -- > <> limit (10 :: Int) | ||
| -- > in buildStatement q userDecoder | ||
| -- | ||
| -- Not that the encoders are specialised to the specific values passed when |
Copilot
AI
Oct 10, 2025
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.
Corrected spelling of 'Not' to 'Note'
| -- Not that the encoders are specialised to the specific values passed when | |
| -- Note that the encoders are specialised to the specific values passed when |
c708597 to
fbed082
Compare
fbed082 to
cc17b85
Compare
cc17b85 to
c228c5c
Compare
In preparation for channel search, this PR introduces a query builder DSL to help construct dynamic postgres queries like those for searching.
It also refactors the existing user group search code to use the DSL.
Checklist
changelog.d