Skip to content

Commit 838a239

Browse files
authored
docs: add example for postgres enums with type TEXT (#3655)
* docs: add example for postgres enums with type TEXT Signed-off-by: tison <wander4096@gmail.com> * revert GitHub naming Signed-off-by: tison <wander4096@gmail.com> * add note Signed-off-by: tison <wander4096@gmail.com> --------- Signed-off-by: tison <wander4096@gmail.com>
1 parent 8b52774 commit 838a239

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

sqlx-postgres/src/types/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,18 @@
179179
//! enum Mood { Sad = 0, Ok = 1, Happy = 2 }
180180
//! ```
181181
//!
182+
//! Rust enumerations may also be defined to be represented as a string using `type_name = "text"`.
183+
//! The following type expects a SQL type of `TEXT` and will convert to/from the Rust enumeration.
184+
//!
185+
//! ```rust,ignore
186+
//! #[derive(sqlx::Type)]
187+
//! #[sqlx(type_name = "text")]
188+
//! enum Mood { Sad, Ok, Happy }
189+
//! ```
190+
//!
191+
//! Note that an error can occur if you attempt to decode a value not contained within the enum
192+
//! definition.
193+
//!
182194
183195
use crate::type_info::PgTypeKind;
184196
use crate::{PgTypeInfo, Postgres};

0 commit comments

Comments
 (0)