Skip to content

Commit

Permalink
add enum with string with mysql backend
Browse files Browse the repository at this point in the history
  • Loading branch information
Ludea committed Jul 18, 2024
1 parent 95fa0fb commit 3a3e61d
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions diesel/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 207,32 @@ where
/// }
/// ```
///
/// Example with String and custom type created by diesel cli
///
/// ```rust
/// pub mod sql_types {
/// #[derive(diesel::sql_types::SqlType)]
/// #[diesel(mysql_type(name = "Enum"))]
/// pub struct PostEnum; <- generated by diesel cli
/// }
/// #[derive(Debug, FromSqlRow, AsExpression, PartialEq, Clone)]
/// #[diesel(sql_type = PostEnum)]
/// pub enum Post {
/// FirstValue,
/// SecondValue,
/// }
///
/// impl ToSql<PostEnum, diesel::mysql::Mysql> for Post {
/// fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, diesel::mysql::Mysql>) -> serialize::Result {
/// match *self {
/// Post::FirstValue => out.write_all(b"one")?,
/// Post::SecondValue => out.write_all(b"two")?,
/// }
/// Ok(IsNull::No)
/// }
/// }
/// ```
///
/// Using temporary values as part of the `ToSql` implementation requires additional
/// work.
///
Expand Down

0 comments on commit 3a3e61d

Please sign in to comment.