From da8b1d9a739000b0d545f5ca92da5099374afe54 Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Mon, 2 Oct 2023 20:54:13 -0400 Subject: [PATCH] Output enum value for sozo model get (#961) --- crates/dojo-types/src/schema.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/dojo-types/src/schema.rs b/crates/dojo-types/src/schema.rs index 715b677c3d..740c39704f 100644 --- a/crates/dojo-types/src/schema.rs +++ b/crates/dojo-types/src/schema.rs @@ -210,7 +210,7 @@ pub struct Enum { } impl Enum { - pub fn to_sql_value(&self) -> Result { + pub fn option(&self) -> Result { let option: usize = if let Some(option) = self.option { option as usize } else { @@ -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 { + Ok(format!("'{}'", self.option()?)) } } @@ -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