Skip to content
Open
Show file tree
Hide file tree
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
33 changes: 33 additions & 0 deletions postgres-derive-test/src/domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,36 @@ fn domain_in_composite() {
)],
);
}

#[test]
fn composite_in_domain_in_composite() {
#[derive(FromSql, ToSql, Debug, PartialEq)]
#[postgres(name = "leaf_composite")]
struct LeafComposite {
prim: i32,
}

#[derive(FromSql, ToSql, Debug, PartialEq)]
#[postgres(name = "domain")]
struct Domain(LeafComposite);

#[derive(FromSql, ToSql, Debug, PartialEq)]
#[postgres(name = "root_composite")]
struct RootComposite {
domain: Domain,
}

let mut conn = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap();
conn.batch_execute("CREATE TYPE leaf_composite AS (prim integer); CREATE DOMAIN domain AS leaf_composite; CREATE TYPE root_composite AS (domain domain);").unwrap();

test_type(
&mut conn,
"root_composite",
&[(
RootComposite {
domain: Domain(LeafComposite { prim: 1 }),
},
"ROW(ROW(1))",
)],
);
}
5 changes: 4 additions & 1 deletion postgres-derive/src/fromsql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ fn domain_accepts_body(name: &str, field: &syn::Field) -> TokenStream {
fn domain_body(ident: &Ident, field: &syn::Field) -> TokenStream {
let ty = &field.ty;
quote! {
<#ty as postgres_types::FromSql>::from_sql(_type, buf).map(#ident)
<#ty as postgres_types::FromSql>::from_sql(match *_type.kind() {
postgres_types::Kind::Domain(ref _type) => _type,
_ => _type
}, buf).map(#ident)
}
}

Expand Down