From b7c7da7d3192e26b6f1cbb5fb0469725ebe4c096 Mon Sep 17 00:00:00 2001 From: Leon Lux Date: Tue, 20 Aug 2024 20:34:57 +0200 Subject: [PATCH 1/5] add information and example on using json in query macros --- sqlx-core/src/types/json.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sqlx-core/src/types/json.rs b/sqlx-core/src/types/json.rs index 5e85092bc7..e46d9222b9 100644 --- a/sqlx-core/src/types/json.rs +++ b/sqlx-core/src/types/json.rs @@ -51,6 +51,32 @@ use crate::types::Type; /// dewey_decimal: sqlx::types::Json> /// } /// ``` +/// +/// If the query macros are used, it is necessary to tell the macro to use +/// the `Json` adapter by using the type override syntax +/// ``` +/// #[derive(sqlx::FromRow] +/// struct Book { +/// title: String, +/// } +/// +/// #[derive(sqlx::FromRow)] +/// struct Author { +/// name: String, +/// books: sqlx::types::Json, +/// } +/// // Note the type override in the query string +/// let authors = sqlx::query_as!( +/// Author, +/// r#" +/// SELECT name, books as "books: Json" +/// FROM authors +/// "# +/// ) +/// .fetch_all(pool) +/// .await?; +/// +/// ``` #[derive( Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize, )] From 523994453280f2c1ccb5a5a1f8621ff88cea08a8 Mon Sep 17 00:00:00 2001 From: Leon Lux Date: Tue, 20 Aug 2024 20:40:25 +0200 Subject: [PATCH 2/5] run cargo format --- sqlx-core/src/types/json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-core/src/types/json.rs b/sqlx-core/src/types/json.rs index e46d9222b9..8e0bf783ff 100644 --- a/sqlx-core/src/types/json.rs +++ b/sqlx-core/src/types/json.rs @@ -51,7 +51,7 @@ use crate::types::Type; /// dewey_decimal: sqlx::types::Json> /// } /// ``` -/// +/// /// If the query macros are used, it is necessary to tell the macro to use /// the `Json` adapter by using the type override syntax /// ``` From 8e930601dc164c07b4e362ff635aa58c1c6753db Mon Sep 17 00:00:00 2001 From: Leon Lux Date: Tue, 20 Aug 2024 20:43:26 +0200 Subject: [PATCH 3/5] add missing bracket to docs of json --- sqlx-core/src/types/json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-core/src/types/json.rs b/sqlx-core/src/types/json.rs index 8e0bf783ff..3690340d94 100644 --- a/sqlx-core/src/types/json.rs +++ b/sqlx-core/src/types/json.rs @@ -55,7 +55,7 @@ use crate::types::Type; /// If the query macros are used, it is necessary to tell the macro to use /// the `Json` adapter by using the type override syntax /// ``` -/// #[derive(sqlx::FromRow] +/// #[derive(sqlx::FromRow)] /// struct Book { /// title: String, /// } From c16d3407786f7d32b5c9d46c31ea92e1ce39c7f1 Mon Sep 17 00:00:00 2001 From: Leon Lux Date: Wed, 21 Aug 2024 18:20:33 +0200 Subject: [PATCH 4/5] wrap docs in hidden async function --- sqlx-core/src/types/json.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sqlx-core/src/types/json.rs b/sqlx-core/src/types/json.rs index 3690340d94..f18372a0b0 100644 --- a/sqlx-core/src/types/json.rs +++ b/sqlx-core/src/types/json.rs @@ -54,7 +54,9 @@ use crate::types::Type; /// /// 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,no_run +/// # async fn example3() -> sqlx::Result<()> { +/// # let mut conn: sqlx::PgConnection = unimplemented!(); /// #[derive(sqlx::FromRow)] /// struct Book { /// title: String, @@ -73,9 +75,10 @@ use crate::types::Type; /// FROM authors /// "# /// ) -/// .fetch_all(pool) +/// .fetch_all(&mut conn) /// .await?; -/// +/// # Ok(()) +/// # } /// ``` #[derive( Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Default, Serialize, Deserialize, From 4b41612b5035c985d0d552cac19ce98b1bd7b1ee Mon Sep 17 00:00:00 2001 From: Leon Lux Date: Wed, 21 Aug 2024 18:27:12 +0200 Subject: [PATCH 5/5] change no_run to ignore --- sqlx-core/src/types/json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlx-core/src/types/json.rs b/sqlx-core/src/types/json.rs index f18372a0b0..fa187f4aab 100644 --- a/sqlx-core/src/types/json.rs +++ b/sqlx-core/src/types/json.rs @@ -54,7 +54,7 @@ use crate::types::Type; /// /// 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,no_run +/// ```rust,ignore /// # async fn example3() -> sqlx::Result<()> { /// # let mut conn: sqlx::PgConnection = unimplemented!(); /// #[derive(sqlx::FromRow)]