Skip to content

Commit

Permalink
PgHasArrayType for transparent types fix. (launchbadge#2086)
Browse files Browse the repository at this point in the history
Problem: PgHasArrayType was checking the application's postgres feature
Solution: only check the library's postgres feature

Co-authored-by: Daniel Tashjian <[email protected]>
  • Loading branch information
2 people authored and Aandreba committed Mar 31, 2023
1 parent ffa0d72 commit c162d24
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions sqlx-macros/src/derives/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn expand_derive_has_sql_type_transparent(
.push(parse_quote!(#ty: ::sqlx::postgres::PgHasArrayType));
let (array_impl_generics, _, array_where_clause) = array_generics.split_for_impl();

return Ok(quote!(
let mut tokens = quote!(
#[automatically_derived]
impl #impl_generics ::sqlx::Type< DB > for #ident #ty_generics #where_clause {
fn type_info() -> DB::TypeInfo {
Expand All @@ -88,15 +88,21 @@ fn expand_derive_has_sql_type_transparent(
<#ty as ::sqlx::Type<DB>>::compatible(ty)
}
}
#[automatically_derived]
#[cfg(feature = "postgres")]
impl #array_impl_generics ::sqlx::postgres::PgHasArrayType for #ident #ty_generics
#array_where_clause {
fn array_type_info() -> ::sqlx::postgres::PgTypeInfo {
<#ty as ::sqlx::postgres::PgHasArrayType>::array_type_info()
);

if cfg!(feature = "postgres") {
tokens.extend(quote!(
#[automatically_derived]
impl #array_impl_generics ::sqlx::postgres::PgHasArrayType for #ident #ty_generics
#array_where_clause {
fn array_type_info() -> ::sqlx::postgres::PgTypeInfo {
<#ty as ::sqlx::postgres::PgHasArrayType>::array_type_info()
}
}
}
));
));
}

return Ok(tokens);
}

let mut tts = TokenStream::new();
Expand Down

0 comments on commit c162d24

Please sign in to comment.