Expand description
Support for custom column types stored as text — the common case being a
Rust enum persisted as a string ("pending", "verified", …).
Implement StringColumn for your type (how it maps to/from a string),
then impl_string_column!(YourType) to wire it into the ORM: it gets a
Text SqlType, and ToColumn /
FromColumn impls (for both T and Option<T>) so it
can be a #[derive(Entity)] field like any primitive.
ⓘ
use rainier_orm::{StringColumn, impl_string_column, Result, Error};
#[derive(Clone, PartialEq)]
enum Status { Pending, Verified, Rejected }
impl StringColumn for Status {
fn to_column_str(&self) -> String {
match self { Status::Pending => "pending", Status::Verified => "verified", Status::Rejected => "rejected" }.into()
}
fn from_column_str(s: &str) -> Result<Self> {
match s {
"pending" => Ok(Status::Pending),
"verified" => Ok(Status::Verified),
"rejected" => Ok(Status::Rejected),
other => Err(Error::msg(format!("unknown Status `{other}`"))),
}
}
}
impl_string_column!(Status);Traits§
- String
Column - How a custom type maps to and from its stored string form. The string is
what lands in a
TEXT/VARCHARcolumn.