Skip to content

Fix Where clause with enum supabase-community/supabase-csharp#66 #72

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

Merged
merged 1 commit into from
Aug 3, 2023

Conversation

elrhomariyounes
Copy link
Contributor

What kind of change does this PR introduce?

supabase-community/supabase-csharp#66
Fix this bug when trying to perform a Where using enums

What is the current behavior?

Not working. A workaround using the EnumMember attribute to get the value and use it with Filter method

What is the new behavior?

As described in the bug. Being able to use Enums in the where clause.

@acupofjose
Copy link
Contributor

Appreciate your work on this!

Question: it looks like the enum must match exactly the enum in postgresql. It looks like some projects use different naming conventions for enums between postgres vs. c#. Should we add support for reading a value from a [MapTo("value")] attribute or a [StringValue("value"] attribute?

i.e. given a postgres enum of:

CREATE TYPE mood AS ENUM ('sad', 'ok', 'happy');

Should we support the c# enum as:

public enum Mood {
    [MapTo("sad")]   
    Sad,
    [MapTo("happy")]
    Happy,
    // ...
}

Thoughts?

@elrhomariyounes
Copy link
Contributor Author

Thank you for taking time to review.

Regarding the question of supporting different naming conventions for enums between PostgreSQL and C#, I have given this some thought and would like to share my perspectives on this matter:

  • To ensure the most straightforward and predictable behavior, it is reasonable to place the responsibility on the consumer to maintain matching enum names between PostgreSQL and C#. I think all package clients would expect enum values to map directly without any additional configuration.

  • I think also in some edge cases we need to make it clear in the documentation on how enums are handled.

  • The idea of adding an attribute to map the c# enum with PostgreSQL one we can implement it as a configuration options, enabling clients to specify custom mapping rules in next releases.

@acupofjose
Copy link
Contributor

  • To ensure the most straightforward and predictable behavior, it is reasonable to place the responsibility on the consumer to maintain matching enum names between PostgreSQL and C#. I think all package clients would expect enum values to map directly without any additional configuration.

That's fair and I agree. Good point!

@acupofjose acupofjose merged commit afca7ea into supabase-community:master Aug 3, 2023
@acupofjose
Copy link
Contributor

Much appreciated @elrhomariyounes!

@elrhomariyounes elrhomariyounes deleted the fixWhereEnum branch August 3, 2023 18:35
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.

2 participants