diff --git a/sqlx-core/src/from_row.rs b/sqlx-core/src/from_row.rs index 08246bbc8a..82ebd9c98e 100644 --- a/sqlx-core/src/from_row.rs +++ b/sqlx-core/src/from_row.rs @@ -123,6 +123,41 @@ use crate::row::Row; /// /// This field is compatible with the `default` attribute. /// +/// #### `skip` +/// +/// This is a variant of the `default` attribute which instead always takes the value from +/// the `Default` implementation for this field type ignoring any results in your query. +/// This can be useful, if some field does not satifisfy the trait bounds (i.e. +/// `sqlx::decode::Decode`, `sqlx::type::Type`), in particular in case of nested structures. +/// For example: +/// +/// ```rust,ignore +/// #[derive(sqlx::FromRow)] +/// struct Address { +/// user_name: String, +/// street: String, +/// city: String, +/// } +/// +/// #[derive(sqlx::FromRow)] +/// struct User { +/// name: String, +/// #[sqlx(skip)] +/// addresses: Vec
, +/// } +/// ``` +/// +/// Then when querying into `User`, only `name` needs to be set: +/// +/// ```rust,ignore +/// let user: User = sqlx::query_as("SELECT name FROM users") +/// .fetch_one(&mut some_connection) +/// .await?; +/// +/// `Default` for `Vec` is an empty vector. +/// assert!(user.addresses.is_empty()); +/// ``` +/// /// ## Manual implementation /// /// You can also implement the [`FromRow`] trait by hand. This can be useful if you diff --git a/sqlx-macros-core/src/derives/attributes.rs b/sqlx-macros-core/src/derives/attributes.rs index bf3c126c45..bfbc32f60d 100644 --- a/sqlx-macros-core/src/derives/attributes.rs +++ b/sqlx-macros-core/src/derives/attributes.rs @@ -63,6 +63,7 @@ pub struct SqlxChildAttributes { pub default: bool, pub flatten: bool, pub try_from: Option