Replies: 2 comments
-
Related variation: 0d4bb39 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hey @gmhafiz! Adding here my comment from our Discord:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When building a query, there are cases when you want to add further query builder(s) if and only if certain conditions are met. In sql, we can use
CASE
operator. But this solution generalize to other database systems.For an example, currently if we are deciding whether to paginate or not, we check the condition is true in the business logic:
While this is clear what it is doing, I feel it can be improved. For example:
q
variables are now on four column levels, reducing readability because the variables are not in a single happy path https://medium.com/@matryer/line-of-sight-in-code-186dd7cdea88q
, condition check, execute)Using a
When()
query builder will turn the code intoIn my opinion, this looks more elegant for the reason:
q
.As far as i know, other ORMs that have a
When()
builder areOther popular ORMs that do not have it AFAIK, are
Implementing it is easy. Only 7 additional lines are required to
query.tmpl
. It takes 7 out of 589 lines inuser_query.go
.I also have a test for it, in which you can review a pull request if this new functionality is desirable.
Beta Was this translation helpful? Give feedback.
All reactions