supabase-community / postgrest-csharp

A C# Client library for Postgrest
https://supabase-community.github.io/postgrest-csharp/api/Postgrest.html
MIT License
114 stars 22 forks source link

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

Closed elrhomariyounes closed 10 months ago

elrhomariyounes commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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:

acupofjose commented 10 months ago
  • 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 commented 10 months ago

Much appreciated @elrhomariyounes!