Skip to content

Commit

Permalink
schema grpc
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Dec 17, 2024
1 parent 5e62115 commit 8da21e7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/torii/grpc/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ fn build_composite_clause(
ClauseType::Member(member) => {
let comparison_operator = ComparisonOperator::from_repr(member.operator as usize)
.expect("invalid comparison operator");
let value = member.value.clone();
let value = member.comparison.value.clone();
let comparison_value =
match value.ok_or(QueryError::MissingParam("value".into()))?.value_type {
Some(ValueType::String(value)) => value,
Expand Down
25 changes: 20 additions & 5 deletions crates/torii/grpc/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ pub enum MemberValue {
String(String),
}

impl TryFrom<proto::types::MemberValue> for MemberValue {
type Error = SchemaError;
fn try_from(value: proto::types::MemberValue) -> Result<Self, Self::Error> {
Ok(match value.value_type {
Some(proto::types::member_value::ValueType::Primitive(primitive)) => MemberValue::Primitive(primitive.try_into()?),
Some(proto::types::member_value::ValueType::String(string)) => MemberValue::String(string),
None => return Err(SchemaError::MissingExpectedData("value_type".into())),
})
}
}

impl fmt::Display for MemberValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down Expand Up @@ -420,13 +431,17 @@ impl From<proto::types::ModelKeysClause> for ModelKeysClause {
}
}

impl From<MemberClause> for proto::types::MemberClause {
fn from(value: MemberClause) -> Self {
Self {
impl TryFrom<proto::types::MemberClause> for MemberClause {
type Error = SchemaError ;
fn try_from(value: proto::types::MemberClause) -> Result<Self, Self::Error> {
Ok(Self {
model: value.model,
member: value.member,
comparison: Some(value.comparison.into()),
}
comparison: match value.comparison {
Some(comparison) => comparison.try_into()?,
None => return Err(SchemaError::MissingExpectedData("comparison".into())),
},
})
}
}

Expand Down

0 comments on commit 8da21e7

Please sign in to comment.