Skip to content

Commit

Permalink
Docs for skip attribute of FromRow macro
Browse files Browse the repository at this point in the history
  • Loading branch information
grgi committed Mar 3, 2023
1 parent 0a16742 commit 8929f74
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions sqlx-core/src/from_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,44 @@ 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<Address>,
/// }
/// ```
///
/// Given 2 querys
///
/// ```sql
/// SELECT name FROM users;
/// ```
///
/// and
///
/// ```sql
/// SELECT user_name, street, city addresses;
/// ```
///
/// the addresses can be assigned to the empty `addresses` field of each `User`.
///
/// ## Manual implementation
///
/// You can also implement the [`FromRow`] trait by hand. This can be useful if you
Expand Down

0 comments on commit 8929f74

Please sign in to comment.