Repository: launchbadge/sqlx
File: src/macros/mod.rs (Rust)

Code before:
///
/// ```rust,ignore
/// # async fn main() {
/// # let mut conn = panic!();
/// // Ironically this is the exact column we primarily look at to determine nullability in Postgres
/// let record = sqlx::query!(
///     r#"select attnotnull as "attnotnull?" from (values (1)) ids left join pg_attribute on false"#
/// )
/// .fetch_one(&mut conn)
/// .await?;
///
/// // Although we do our best, under Postgres this might have been inferred to be `bool`
/// // In that case, we would have gotten an error
/// assert_eq!(record.attnotnull, None);
/// # }
/// ```
///
/// If you find that you need to use this override, please open an issue with a query we can use
/// to reproduce the problem. For Postgres users, especially helpful would be the output of
/// `EXPLAIN (VERBOSE, FORMAT JSON) <your query>` with bind parameters substituted in the query
/// (as the exact value of bind parameters can change the query plan)
/// and the definitions of any relevant tables (or sufficiently anonymized equivalents).
///
/// ##### Force a Different/Custom Type
/// Selecting a column `foo as "foo: T"` (Postgres / SQLite) or `` foo as `foo: T` `` (MySQL)
/// overrides the inferred type which is useful when selecting user-defined [`custom types`][crate::Type#compile-time-verification]
/// (dynamic type checking is still done so if the types are incompatible this will be an error
/// at runtime instead of compile-time). Note that this syntax alone doesn't override inferred nullability,
/// but it is compatible with the forced not-null and forced nullable annotations:
///
/// ```rust,ignore
/// # async fn main() {
/// # let mut conn = panic!();
/// #[derive(sqlx::Type)]
/// #[sqlx(transparent)]
/// struct MyInt4(i32);
///
/// let my_int = MyInt4(1);
///
/// // Postgres/SQLite
/// sqlx::query!(r#"select 1 as "id!: MyInt4""#) // MySQL: use "select 1 as `id: MyInt4`" instead
///     .fetch_one(&mut conn)
///     .await?;
///
/// // For Postgres this would have been inferred to be `Option<i32>`, MySQL/SQLite `i32`
/// // Note that while using `id: MyInt4` (without the `!`) would work the same for MySQL/SQLite,
/// // Postgres would expect `Some(MyInt4(1))` and the code wouldn't compile
/// assert_eq!(record.id, MyInt4(1));
/// # }
/// ```
///

Review comment (suggestion):
```suggestion
/// overrides the inferred type which is useful when selecting user-defined [custom types][crate::Type#compile-time-verification]
```

Backticks aren't necessary for all links.

Code after:
///
/// ```rust,ignore
/// # async fn main() {
/// # let mut conn = panic!();
/// // Ironically this is the exact column we primarily look at to determine nullability in Postgres
/// let record = sqlx::query!(
///     r#"select attnotnull as "attnotnull?" from (values (1)) ids left join pg_attribute on false"#
/// )
/// .fetch_one(&mut conn)
/// .await?;
///
/// // Although we do our best, under Postgres this might have been inferred to be `bool`
/// // In that case, we would have gotten an error
/// assert_eq!(record.attnotnull, None);
/// # }
/// ```
///
/// If you find that you need to use this override, please open an issue with a query we can use
/// to reproduce the problem. For Postgres users, especially helpful would be the output of
/// `EXPLAIN (VERBOSE, FORMAT JSON) <your query>` with bind parameters substituted in the query
/// (as the exact value of bind parameters can change the query plan)
/// and the definitions of any relevant tables (or sufficiently anonymized equivalents).
///
/// ##### Force a Different/Custom Type
/// Selecting a column `foo as "foo: T"` (Postgres / SQLite) or `` foo as `foo: T` `` (MySQL)
/// overrides the inferred type which is useful when selecting user-defined [custom types][crate::Type#compile-time-verification]
/// (dynamic type checking is still done so if the types are incompatible this will be an error
/// at runtime instead of compile-time). Note that this syntax alone doesn't override inferred nullability,
/// but it is compatible with the forced not-null and forced nullable annotations:
///
/// ```rust,ignore
/// # async fn main() {
/// # let mut conn = panic!();
/// #[derive(sqlx::Type)]
/// #[sqlx(transparent)]
/// struct MyInt4(i32);
///
/// let my_int = MyInt4(1);
///
/// // Postgres/SQLite
/// sqlx::query!(r#"select 1 as "id!: MyInt4""#) // MySQL: use "select 1 as `id: MyInt4`" instead
///     .fetch_one(&mut conn)
///     .await?;
///
/// // For Postgres this would have been inferred to be `Option<i32>`, MySQL/SQLite `i32`
/// // Note that while using `id: MyInt4` (without the `!`) would work the same for MySQL/SQLite,
/// // Postgres would expect `Some(MyInt4(1))` and the code wouldn't compile
/// assert_eq!(record.id, MyInt4(1));
/// # }
/// ```
///