Skip to main content

PgComposite

Derive Macro PgComposite 

Source
#[derive(PgComposite)]
{
    // Attributes available to this derive:
    #[orm]
}
Expand description

Derive PgComposite helpers to map a Rust struct to a PostgreSQL composite type.

§Example

use pgorm::PgComposite;

#[derive(PgComposite, Debug, Clone)]
#[orm(pg_type = "address")]
pub struct Address {
    pub street: String,
    pub city: String,
    pub zip_code: String,
    pub country: String,
}

§Generated

  • impl ToSql for Address
  • impl<'a> FromSql<'a> for Address
  • impl PgType for Address (returns "{pg_type}[]")

§Attributes

Struct-level:

  • #[orm(pg_type = "name")] - PostgreSQL composite type name (required)

§Limitations

  • Only flat structs with named fields are supported.
  • Nested composite types are not supported.
  • All fields must implement ToSql and FromSql.