-
Notifications
You must be signed in to change notification settings - Fork 36
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
Support "if" and pattern match in where condition #89
Conversation
While that is technically very impressive, it seems like a pretty heavy-handed approach for what it accomplishes (conditional where statements) and would add a fair amount of additional complexity. Have you at least considered a It has been discussed in the SqlHydra repo (which uses the same engine) here: Not to say that it's not worth doing, but maybe worth considering the simpler alternatives. Just my $0.02. |
Yes, we was using similar updateWhereIf And firstNameFilter.IsSome (like p.FirstName firstNameFilter.Value) I don't see a way how to solve this problem without extending Another problem is that if you want to combine different operators it's got ugly. Regarding complexity, IMO it's not much complexity added, main logic of I could revisit naming and comments there, if that would be main problem. |
I don't follow why that would be a problem. The
My opinion on the design is that users can safely leverage the entirety of the F# language features outside the On the other hand, keeping it streamlined to a narrow set of supported language features avoids this pitfall.
I guess it just depends on how committed you are to the vision of building and maintaining a fully-fledged F# expression parser. It just seems to me that there are simpler ways of achieving conditional The SQLProvider codebase provides a very full featured expression parser, and it's really amazing. When I was working on that codebase and admiring the parser, I thought, "nah... I wouldn't want to maintain that." lol! But maybe if you are volunteering to fix any bugs... 🤔 |
If you go this route, you should also consider adding a matrix of which F# language features that are supported and which are not within the expressions to the docs so that users have a guideline of what is actually possible without leading to runtime errors. |
Point is that without this feature, the only way how to construct
I understand your position, I really didn't think about it from this perspective. But I am not convinced it's a bad idea. Users raising issue about what they consider a bug all the time :) But its not super important for me to do it this way, maybe I could figure out how to support
README works as list of supported features. If we go this route, I think some warning that "creative" expression can lead to runtime error is in order. And maybe pointing on docs from exception. I'll wait what @Dzoukr thinks about this and then improve docs or scratch it. |
Good point. It will probably be fine either way. 👍 |
For the record, this is what I was imagining the alternative might look like: select {
for p in personTable do
whereIf positionGTFilter.IsSome (p.Position > positionGTFilter.Value)
andWhereIf positionLTFilter.IsSome (p.Position < positionLTFilter.Value)
andWhereIf firstNameFilter.IsSome (like p.FirstName firstNameFilter.Value)
} |> conn.SelectAsync<Person> More or less... Then again, this might be the most readable approach to handle conditional where statements, and it's also the closest to what you would do if writing SQL: 🤔 select {
for p in personTable do
where (
(positionGTFilter.IsSome && p.Position > positionGTFilter.Value) &&
(positionLTFilter.IsSome && p.Position < positionLTFilter.Value) &&
(firstNameFilter.IsSome && (like p.FirstName firstNameFilter.Value))
)
} |> conn.SelectAsync<Person> |
I see that vacation time has been productive (you, not me 😄) Sooo, long story short, I am "team Jordan" here. The initial purpose of this library remains - keep. it. simple! My two cents:
What do you think? I have been away for a long time, so may be slightly slow today. 😄 |
Ok, I'll make new PR with these custom operations. I still don't like the need of @Dzoukr Should I separate it in 2 PRs:
or it can be in one PR? |
Main motivation for this feature is combining
where
condition from optional parameters:It's adding support for:
if
...then
...else
, where condition needs to be ofbool
typetrue
,false
)match
expression is actually translated toif
expressions inLinq.Expression
Option
,Result
and simple custom DU is covered by tests, its quite possible there is more corner cases that's not covered by thisvisitWhere
(so we are able to replacex
with value frompositionGTFilter
inp.Position > x
. It can be used to support lambda functions in other use cases in the future.✅Whole test suite is green on MyComputer™.