diff --git a/sqlx-macros-core/src/derives/attributes.rs b/sqlx-macros-core/src/derives/attributes.rs index a0f08b1aab..31818d3469 100644 --- a/sqlx-macros-core/src/derives/attributes.rs +++ b/sqlx-macros-core/src/derives/attributes.rs @@ -236,12 +236,6 @@ pub fn check_enum_attributes(input: &DeriveInput) -> syn::Result ::sqlx::postgres::PgTypeInfo { + ::sqlx::postgres::PgTypeInfo::with_name(#array_ty_name) + } + } + )); + } } if cfg!(feature = "sqlite") { @@ -235,3 +247,21 @@ fn type_name(ident: &Ident, explicit_name: Option<&TypeName>) -> TokenStream { quote_spanned!(ident.span()=> #s) }) } + +fn pg_array_type_name(ident: &Ident, explicit_name: Option<&TypeName>) -> TokenStream { + explicit_name + .map(|tn| { + let s = pg_array_type_name_from_type_name(&tn.val); + quote! { #s } + }) + .unwrap_or_else(|| { + let s = pg_array_type_name_from_type_name(&ident.to_string()); + quote_spanned!(ident.span()=> #s) + }) +} + +fn pg_array_type_name_from_type_name(name: &str) -> String { + name.split_once('.') + .map(|(schema, name)| format!("{}._{}", schema, name)) + .unwrap_or_else(|| format!("_{}", name)) +} diff --git a/tests/postgres/describe.rs b/tests/postgres/describe.rs index d128eb21b6..71d9a76376 100644 --- a/tests/postgres/describe.rs +++ b/tests/postgres/describe.rs @@ -52,7 +52,7 @@ async fn it_describes_enum() -> anyhow::Result<()> { let ty = d.columns()[0].type_info(); - assert_eq!(ty.name(), "status"); + assert_eq!(ty.name(), "public.status"); assert_eq!( format!("{:?}", ty.kind()),