sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

[Postgres] Auto-implement PgHasArrayType for enums deriving Type

Open michalmoc opened this issue 2 years ago • 1 comments

derive(sqlx::Type) already can auto-implement PgHasArrayType for wrapper types, and I believe it should be fairly easy to add the same functionality for enums. Code illustration

#[derive(sqlx::Type)]
#[sqlx(type_name = "weekday", rename_all = "lowercase")]
enum Weekday {
    Sunday,
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
}

impl PgHasArrayType for Weekday {
    fn array_type_info() -> PgTypeInfo {
        PgTypeInfo::with_name("weekday[]")
    }
}

We already know the postgres custom type name (type_name = "weekday") and have to only add the array marker [].

Part of #298.

michalmoc avatar Jan 22 '24 16:01 michalmoc

It looks like this may be done with https://github.com/launchbadge/sqlx/pull/3603/ ?

genevieve-me avatar Oct 31 '25 21:10 genevieve-me