sqlx
sqlx copied to clipboard
[Postgres] Auto-implement PgHasArrayType for enums deriving Type
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.
It looks like this may be done with https://github.com/launchbadge/sqlx/pull/3603/ ?