Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs for postgres composite types #3547

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion sqlx-core/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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<DB: Database> {
/// Returns the canonical SQL type for this Rust type.
///
Expand Down
Loading