diff --git a/sqlx-core/src/from_row.rs b/sqlx-core/src/from_row.rs index 973c4b33..2c2ce3a7 100644 --- a/sqlx-core/src/from_row.rs +++ b/sqlx-core/src/from_row.rs @@ -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, diff --git a/sqlx-core/src/types/mod.rs b/sqlx-core/src/types/mod.rs index 92a512ac..4e21d115 100644 --- a/sqlx-core/src/types/mod.rs +++ b/sqlx-core/src/types/mod.rs @@ -98,6 +98,14 @@ pub use json::Json; /// struct UserId(i64); /// ``` /// +/// ##### Attributes +/// +/// * `#[sqlx(rename = "")]` on struct definition: instead of inferring the SQL type name from the inner +/// field (in the above case, `BIGINT`), explicitly set it to `` 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