mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
parent
1af26d8350
commit
f5392151f3
2 changed files with 30 additions and 1 deletions
|
@ -60,6 +60,8 @@ fn expand_derive_has_sql_type_transparent(
|
|||
|
||||
if attr.transparent {
|
||||
let mut generics = generics.clone();
|
||||
let mut array_generics = generics.clone();
|
||||
|
||||
generics
|
||||
.params
|
||||
.insert(0, parse_quote!(DB: ::sqlx::Database));
|
||||
|
@ -67,9 +69,14 @@ fn expand_derive_has_sql_type_transparent(
|
|||
.make_where_clause()
|
||||
.predicates
|
||||
.push(parse_quote!(#ty: ::sqlx::Type<DB>));
|
||||
|
||||
let (impl_generics, _, where_clause) = generics.split_for_impl();
|
||||
|
||||
array_generics
|
||||
.make_where_clause()
|
||||
.predicates
|
||||
.push(parse_quote!(#ty: ::sqlx::postgres::PgHasArrayType));
|
||||
let (array_impl_generics, _, array_where_clause) = array_generics.split_for_impl();
|
||||
|
||||
return Ok(quote!(
|
||||
#[automatically_derived]
|
||||
impl #impl_generics ::sqlx::Type< DB > for #ident #ty_generics #where_clause {
|
||||
|
@ -81,6 +88,14 @@ 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()
|
||||
}
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,20 @@ use std::ops::Bound;
|
|||
#[sqlx(transparent)]
|
||||
struct Transparent(i32);
|
||||
|
||||
#[sqlx_macros::test]
|
||||
async fn test_transparent_slice_to_array() -> anyhow::Result<()> {
|
||||
let mut conn = new::<Postgres>().await?;
|
||||
|
||||
let values = vec![Transparent(1), Transparent(2), Transparent(3)];
|
||||
|
||||
sqlx::query("SELECT 2 = ANY($1);")
|
||||
.bind(&values)
|
||||
.fetch_one(&mut conn)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// "Weak" enums map to an integer type indicated by #[repr]
|
||||
#[derive(PartialEq, Copy, Clone, Debug, sqlx::Type)]
|
||||
#[repr(i32)]
|
||||
|
|
Loading…
Reference in a new issue