Skip to content

Conversation

gronke
Copy link

@gronke gronke commented Oct 13, 2024

PR Info

New Features

  • IF ELSE statements

Breaking Changes

  • Add SimpleExpr::IfElse variant to public enum

Copy link
Member

@Expurple Expurple left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't reviewed the rest yet. Consider running cargo semver-checks to find and document the breaking changes.

Disclaimer: I'm not a maintainer

@gronke gronke mentioned this pull request May 16, 2025
10 tasks
@Expurple Expurple mentioned this pull request May 22, 2025
4 tasks
Comment on lines +396 to +399
/// Prefix of the ELSEIF (MySQL) vs ELSIF (Postgres) keyword
fn elseif_keyword_prefix(&self) -> &str {
panic!("ELSEIF/ELSIF keyword prefix not implemented for this backend");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this panic. See #829 (comment). Although, I don't know anything about the backend design in sea_query. Maybe that's just how we do things here.

Maybe, SimpleExpr just shouldn't contain non-portable variants and we should come up with a different way of handling IfElseStatement.

@tyt2y3 @Huliiiiii, do you have any thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, our usual approach is to panic when features are not supported.

There are two ways to solve this problem:

  1. Make IfElseStatement behind the feature gate
  2. Modify these kind of functions to return result (breaking)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make IfElseStatement behind the feature gate

I think, it doesn't solve all the issues. It's nice that you won't be able to use if-else if you activate only sqlite backend. But if you activate e.g. sqlite+postgres backends, then this syntax becomes available and you can pass it to the sqlite backend and hit a runtime panic.

Ideally, it should be impossible to pass. But I'm not sure how achievable for us and convenient for the user is that. Someone needs to experiment and document the results.

Modify these kind of functions to return result (breaking)

This is a more achievable route that we could explore and see if it's annoying for the user. Sadly, I don't have time for this right now

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could implement backend specific features, closely resembling local specifics. Later then we could build a general IfElseStatement that normalizes the expression of logic and polyfills for each backend.

My personal use case for If-Else statements are triggers. Triggers could be made conditional on SQLite with WHEN clauses by splitting up the one trigger into multiple. Elsewhere our conditions could break down to CASE expressions. Would love to hear whether that would be a general direction to consider.

Meanwhile we could prepare such step by building backend specific features that only later become available globally. It would be nice to avoid panicking, but it would also be possible to solve that later by introducing a polyfill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants