doc: improve docs for Type and FromRow derives

This commit is contained in:
Austin Bonander 2020-10-27 00:48:34 -07:00
parent 5f793c6e95
commit e44031676f
2 changed files with 27 additions and 0 deletions

View File

@ -47,6 +47,25 @@ use crate::row::Row;
///
/// will read the content of the column `description` into the field `about_me`.
///
/// #### `rename_all`
/// By default, field names are expected verbatim (with the exception of the raw identifier prefix `r#`, if present).
/// Placed at the struct level, this attribute changes how the field name is mapped to its SQL column name:
///
/// ```rust,ignore
/// #[derive(sqlx::FromRow)]
/// #[sqlx(rename_all = "camelCase")]
/// struct UserPost {
/// id: i32,
/// // remapped to "userId"
/// user_id: i32,
/// contents: String
/// }
/// ```
///
/// The supported values are `snake_case` (available if you have non-snake-case field names for some
/// reason), `lowercase`, `UPPERCASE`, `camelCase`, `SCREAMING_SNAKE_CASE` and `kebab-case`.
/// The styling of each option is intended to be an example of its behavior.
///
/// #### `default`
///
/// When your struct contains a field that is not present in your query,

View File

@ -98,6 +98,14 @@ pub use json::Json;
/// struct UserId(i64);
/// ```
///
/// ##### Attributes
///
/// * `#[sqlx(rename = "<SQL type name>")]` on struct definition: instead of inferring the SQL type name from the inner
/// field (in the above case, `BIGINT`), explicitly set it to `<SQL type name>` instead. May trigger
/// errors or unexpected behavior if the encoding of the given type is different than that of the
/// inferred type (e.g. if you rename the above to `VARCHAR`).
/// Affects Postgres only.
///
/// ### Enumeration
///
/// Enumerations may be defined in Rust and can match SQL by