Skip to content

[Postgres] Auto-implement PgHasArrayType for enums deriving Type #3003

@michalmoc

Description

@michalmoc

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions