Skip to content

Commit

Permalink
Add Query::key method
Browse files Browse the repository at this point in the history
  • Loading branch information
romac committed Nov 15, 2022
1 parent dfed789 commit 406b48a
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions rpc/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,31 @@ pub enum Condition {
Exists(String),
}

impl Condition {
/// Return the key that this condition applies to
pub fn key(&self) -> &str {
match self {
Self::Eq(key, _) => key,
Self::Lt(key, _) => key,
Self::Lte(key, _) => key,
Self::Gt(key, _) => key,
Self::Gte(key, _) => key,
Self::Contains(key, _) => key,
Self::Exists(key) => key,
}
}
}

impl fmt::Display for Condition {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Condition::Eq(key, op) => write!(f, "{} = {}", key, op),
Condition::Lt(key, op) => write!(f, "{} < {}", key, op),
Condition::Lte(key, op) => write!(f, "{} <= {}", key, op),
Condition::Gt(key, op) => write!(f, "{} > {}", key, op),
Condition::Gte(key, op) => write!(f, "{} >= {}", key, op),
Condition::Contains(key, op) => write!(f, "{} CONTAINS {}", key, escape(op)),
Condition::Exists(key) => write!(f, "{} EXISTS", key),
Self::Eq(key, op) => write!(f, "{} = {}", key, op),
Self::Lt(key, op) => write!(f, "{} < {}", key, op),
Self::Lte(key, op) => write!(f, "{} <= {}", key, op),
Self::Gt(key, op) => write!(f, "{} > {}", key, op),
Self::Gte(key, op) => write!(f, "{} >= {}", key, op),
Self::Contains(key, op) => write!(f, "{} CONTAINS {}", key, escape(op)),
Self::Exists(key) => write!(f, "{} EXISTS", key),
}
}
}
Expand Down

0 comments on commit 406b48a

Please sign in to comment.