Skip to content

Commit

Permalink
Output enum value for sozo model get (#961)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarrencev authored Oct 3, 2023
1 parent ea19c4b commit da8b1d9
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions crates/dojo-types/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub struct Enum {
}

impl Enum {
pub fn to_sql_value(&self) -> Result<String, EnumError> {
pub fn option(&self) -> Result<String, EnumError> {
let option: usize = if let Some(option) = self.option {
option as usize
} else {
Expand All @@ -221,7 +221,11 @@ impl Enum {
return Err(EnumError::OptionInvalid);
}

Ok(format!("'{}'", self.options[option].0))
Ok(self.options[option].0.clone())
}

pub fn to_sql_value(&self) -> Result<String, EnumError> {
Ok(format!("'{}'", self.option()?))
}
}

Expand Down Expand Up @@ -290,6 +294,11 @@ fn format_member(m: &Member) -> String {
}
}
}
} else if let Ty::Enum(e) = &m.ty {
match e.option() {
Ok(option) => str.push_str(&format!(" = {option}")),
Err(_) => str.push_str(" = Invalid Option"),
}
}

str
Expand Down

0 comments on commit da8b1d9

Please sign in to comment.