Skip to content

Commit

Permalink
docs: add example for postgres enums with type TEXT (#3655)
Browse files Browse the repository at this point in the history
* docs: add example for postgres enums with type TEXT

Signed-off-by: tison <[email protected]>

* revert GitHub naming

Signed-off-by: tison <[email protected]>

* add note

Signed-off-by: tison <[email protected]>

---------

Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun authored Jan 15, 2025
1 parent 8b52774 commit 838a239
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions sqlx-postgres/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit 838a239

Please sign in to comment.