-
Notifications
You must be signed in to change notification settings - Fork 3
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
Introduce sqlAll
, sqlAny
and related state types
#112
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.
There are a few hlint warnings btw.
-- | Type representing a set of conditions that are joined by 'AND'. | ||
-- | ||
-- This is usually not needed as the default behavior is to join conditions | ||
-- by 'AND', but it is used to implement `sqlWhereAny`. |
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.
Is it? Is says the same thing about SqlWhereAny, it's a bit confusing.
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 guess I'll remove the implementation details from the comments.
-- | Run monad that joins all conditions with 'AND' operator. | ||
-- | ||
-- When no conditions are given, the result is 'TRUE'. | ||
sqlAll :: State SqlWhereAll () -> SQL |
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.
What is it for? Apart from being used in sqlWhereAny
. Tests?
Because sqlWhere . sqlAll
is redundant.
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.
Well for nesting AND
s in OR
's and parity with sqlAny
. How else are you going to write (a OR (b AND c))
?
I mean, you could use sqlWhereAny
, but if you want to go with sqlWhere . sqlAny $ ...
, then at one point you have to use sqlWhere . sqlAll $ ...
inside.
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.
Ah, I see. The comment you added to the code makes it clear, thanks.
-- | Run monad that joins all conditions with 'OR' operator. | ||
-- | ||
-- When no conditions are given, the result is 'FALSE'. | ||
sqlAny :: State SqlWhereAny () -> SQL |
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.
Perhaps we should deprecate sqlWhereAny
and start using sqlWhere . sqlAny $ do ...
instead?
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.
Depends if you'd like to remove it eventually. But if you want to deprecate sqlWhereAny
, then I'd like to deprecate sqlOR
, sqlConcatAND
and sqlConcatOR
as well.
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 it comes to kontrakcja, sqlOR
is used 1 time, sqlConcatAND
5 times and sqlConcatOR
4 times, so it seems feasible. Let's do it a separate PR though.
This allows writing cartain helper functions which weren't possible before.
Previous commit introduced some inconsistencies in terms of documentation vs implementation for `SqlWhereAny`. For that reason, I dediced to expand on the scope a little bit and introduce `WHERE` wrappers for `AND` and `OR` conditions.
083fba7
to
79de921
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.
Looks good, thanks. Feel free to merge after addressing the comment about empty line in tests.
-- | Run monad that joins all conditions with 'AND' operator. | ||
-- | ||
-- When no conditions are given, the result is 'TRUE'. | ||
sqlAll :: State SqlWhereAll () -> SQL |
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.
Ah, I see. The comment you added to the code makes it clear, thanks.
test/Main.hs
Outdated
, sqlWhere "cond4" | ||
] | ||
] | ||
|
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.
Why the empty line? :)
-- | Run monad that joins all conditions with 'OR' operator. | ||
-- | ||
-- When no conditions are given, the result is 'FALSE'. | ||
sqlAny :: State SqlWhereAny () -> SQL |
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 it comes to kontrakcja, sqlOR
is used 1 time, sqlConcatAND
5 times and sqlConcatOR
4 times, so it seems feasible. Let's do it a separate PR though.
I forgot, please update the PR title (IIUC it's outdated) and add changelog entry. |
sqlAll
, sqlAny
and related state types
This allows writing certain helper functions which weren't possible before.
Specific use case is for filters:
Without the type available, one can only use constraints, but then there's an issue of ambiguous type variables:
Note: I realized later that there's is a way to write the helper, which is by omitting the type signature entirely, but I don't see any reason why this type has to be hidden.