From 3c44ac24404f7c1f36e423b515e95d0c14e115cf Mon Sep 17 00:00:00 2001 From: Dario Heinisch Date: Mon, 3 Jun 2024 17:11:22 +0200 Subject: [PATCH 1/2] Hide docs for any --- sqlx-postgres/src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sqlx-postgres/src/lib.rs b/sqlx-postgres/src/lib.rs index 994693ec9a..c50f53067e 100644 --- a/sqlx-postgres/src/lib.rs +++ b/sqlx-postgres/src/lib.rs @@ -26,6 +26,12 @@ pub mod types; mod value; #[cfg(feature = "any")] +// We are hiding the any module with its AnyConnectionBackend trait +// so that IDEs don't show it in the autocompletion list +// and end users don't accidentally use it. This can result in +// nested transactions not behaving as expected. +// For more information, see https://github.com/launchbadge/sqlx/pull/3254#issuecomment-2144043823 +#[doc(hidden)] pub mod any; #[cfg(feature = "migrate")] From c664a2c798cda52f99a9a66e9dd127a9841c8888 Mon Sep 17 00:00:00 2001 From: Dario Heinisch Date: Sat, 5 Oct 2024 23:13:35 -0700 Subject: [PATCH 2/2] Update docs for composite types in postgres --- sqlx-core/src/types/mod.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sqlx-core/src/types/mod.rs b/sqlx-core/src/types/mod.rs index 25837b1e77..f69e70ae30 100644 --- a/sqlx-core/src/types/mod.rs +++ b/sqlx-core/src/types/mod.rs @@ -181,8 +181,15 @@ pub use text::Text; /// ### Records /// /// User-defined composite types are supported through deriving a `struct`. -/// /// This is only supported for PostgreSQL. +/// +/// Note Composite types are being encoded as tuples in the order as the fields of the struct are defined. +/// Therefore the fields of the struct must be in the same order as the composite type has been defined +/// as otherwise the encoding when binding a composite type will fail. +/// +/// ```sql +/// create type interface_type (name varchar, supplier_id int, price float); +/// ``` /// /// ```rust,ignore /// #[derive(sqlx::Type)] @@ -193,6 +200,19 @@ pub use text::Text; /// price: f64 /// } /// ``` +/// +/// ```rust,ignore +/// // This will fail when binding the struct to a query as parameter. +/// // The fields are not in the same order as the composite type +/// // resulting in encoding the struct as: `(supplier_id, name, price)` +/// #[derive(sqlx::Type)] +/// #[sqlx(type_name = "interface_type")] +/// struct WillFail { +/// supplier_id: i32, +/// name: String, +/// price: f64 +/// } +/// ``` pub trait Type { /// Returns the canonical SQL type for this Rust type. ///