Skip to content

Commit 15713ba

Browse files
committed
Docs for skip attribute of FromRow macro
1 parent 0a16742 commit 15713ba

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

sqlx-core/src/from_row.rs

+39-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,45 @@ use crate::row::Row;
123123
///
124124
/// This field is compatible with the `default` attribute.
125125
///
126-
/// ## Manual implementation
126+
/// #### `skip`
127+
///
128+
/// This is a variant of the `default` attribute which instead always takes the value from
129+
/// the `Default` implementation for this field type ignoring any results in your query.
130+
/// This can be useful, if some field does not satifisfy the trait bounds (i.e.
131+
/// `sqlx::decode::Decode`, `sqlx::type::Type`), in particular in case of nested structures.
132+
/// For example:
133+
///
134+
/// ```rust,ignore
135+
/// #[derive(sqlx::FromRow)]
136+
/// struct Address {
137+
/// user_name: String,
138+
/// street: String,
139+
/// city: String,
140+
/// }
141+
///
142+
/// #[derive(sqlx::FromRow)]
143+
/// struct User {
144+
/// name: String,
145+
/// #[sqlx(skip)]
146+
/// addresses: Vec<Address>,
147+
/// }
148+
/// ```
149+
///
150+
/// Given 2 querys
151+
///
152+
/// ```sql
153+
/// SELECT name FROM users;
154+
/// ```
155+
///
156+
/// and
157+
///
158+
/// ```sql
159+
/// SELECT user_name, street, city addresses;
160+
/// ```
161+
///
162+
/// the addresses can be assigned to the empty `addresses` field of each `User`.
163+
///
164+
////// ## Manual implementation
127165
///
128166
/// You can also implement the [`FromRow`] trait by hand. This can be useful if you
129167
/// have a struct with a field that needs manual decoding:

0 commit comments

Comments
 (0)