From 838a239a2ca9bee0a4c1a78806589a7197916408 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 16 Jan 2025 00:41:57 +0800 Subject: [PATCH] docs: add example for postgres enums with type TEXT (#3655) * docs: add example for postgres enums with type TEXT Signed-off-by: tison * revert GitHub naming Signed-off-by: tison * add note Signed-off-by: tison --------- Signed-off-by: tison --- sqlx-postgres/src/types/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sqlx-postgres/src/types/mod.rs b/sqlx-postgres/src/types/mod.rs index 26feb055..74734551 100644 --- a/sqlx-postgres/src/types/mod.rs +++ b/sqlx-postgres/src/types/mod.rs @@ -179,6 +179,18 @@ //! enum Mood { Sad = 0, Ok = 1, Happy = 2 } //! ``` //! +//! Rust enumerations may also be defined to be represented as a string using `type_name = "text"`. +//! The following type expects a SQL type of `TEXT` and will convert to/from the Rust enumeration. +//! +//! ```rust,ignore +//! #[derive(sqlx::Type)] +//! #[sqlx(type_name = "text")] +//! enum Mood { Sad, Ok, Happy } +//! ``` +//! +//! Note that an error can occur if you attempt to decode a value not contained within the enum +//! definition. +//! use crate::type_info::PgTypeKind; use crate::{PgTypeInfo, Postgres};