mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-10 06:24:16 +00:00
Clarify usage of Json/Jsonb in query macros (#3447)
* add information and example on using json in query macros * run cargo format * add missing bracket to docs of json * wrap docs in hidden async function * change no_run to ignore
This commit is contained in:
parent
1fb255935f
commit
f69f370f25
1 changed files with 29 additions and 0 deletions
|
@ -51,6 +51,35 @@ use crate::types::Type;
|
|||
/// dewey_decimal: sqlx::types::Json<HashMap<String, Book>>
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// If the query macros are used, it is necessary to tell the macro to use
|
||||
/// the `Json` adapter by using the type override syntax
|
||||
/// ```rust,ignore
|
||||
/// # async fn example3() -> sqlx::Result<()> {
|
||||
/// # let mut conn: sqlx::PgConnection = unimplemented!();
|
||||
/// #[derive(sqlx::FromRow)]
|
||||
/// struct Book {
|
||||
/// title: String,
|
||||
/// }
|
||||
///
|
||||
/// #[derive(sqlx::FromRow)]
|
||||
/// struct Author {
|
||||
/// name: String,
|
||||
/// books: sqlx::types::Json<Book>,
|
||||
/// }
|
||||
/// // Note the type override in the query string
|
||||
/// let authors = sqlx::query_as!(
|
||||
/// Author,
|
||||
/// r#"
|
||||
/// SELECT name, books as "books: Json<Book>"
|
||||
/// FROM authors
|
||||
/// "#
|
||||
/// )
|
||||
/// .fetch_all(&mut conn)
|
||||
/// .await?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// ```
|
||||
#[derive(
|
||||
Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize,
|
||||
)]
|
||||
|
|
Loading…
Reference in a new issue