Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PgHasArrayType for transparent types fix. #2086

Merged
merged 1 commit into from
Sep 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was making it so my application had to have a postgres feature which was enabled. 💢

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woops! Good catch.

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