Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 65 additions & 29 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ serde_json = "1.0"
serde = "1.0"
libc = "0.2"
jsonpath_lib = { git="https://github.com/RedisJSON/jsonpath.git", branch="generic_json_path" }
redis-module = { version="0.21", features = ["experimental-api"]}
redis-module = { version="0.22", features = ["experimental-api"]}
[features]
# Workaround to allow cfg(feature = "test") in redismodue-rs dependencies:
# https://github.com/RedisLabsModules/redismodule-rs/pull/68
Expand Down
15 changes: 7 additions & 8 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,14 @@ impl<'a, V: SelectValue> KeyValue<'a, V> {
})])
} else {
// Adding somewhere in existing object, use jsonpath_lib::replace_with
let p = parsed_static_path
.static_path_elements
.iter()
.map(|e| e.to_string())
.collect::<Vec<_>>()
.join("");
let mut selector = Selector::default();
if let Err(e) = selector.str_path(
&parsed_static_path
.static_path_elements
.iter()
.map(|e| e.to_string())
.collect::<Vec<String>>()
.join(""),
) {
if let Err(e) = selector.str_path(&p) {
return Err(e.into());
}
selector.value(self.val);
Expand Down
24 changes: 17 additions & 7 deletions src/nodevisitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ pub enum VisitStatus {
Valid,
}

pub struct StaticPathParser {
pub struct StaticPathParser<'a> {
pub valid: VisitStatus,
last_token: Option<ParseToken>,
last_token: Option<ParseToken<'a>>,
pub static_path_elements: Vec<StaticPathElement>,
}

impl StaticPathParser {
impl<'a> StaticPathParser<'a> {
///
/// Checks if path is static & valid
///
pub fn check(input: &str) -> Result<Self, String> {
pub fn check(input: &'a str) -> Result<Self, String> {
let node = Parser::compile(input)?;
let mut visitor = StaticPathParser {
valid: VisitStatus::PartialValid,
Expand All @@ -49,8 +49,8 @@ impl StaticPathParser {
}
}

impl NodeVisitor for StaticPathParser {
fn visit_token(&mut self, token: &ParseToken) {
impl<'a> NodeVisitor<'a> for StaticPathParser<'a> {
fn visit_token(&mut self, token: &ParseToken<'a>) {
if self.valid != VisitStatus::NotValid {
//eprintln!("visit token: {:?} -> {:?}", self.last_token, token);
self.valid = match (&self.last_token, token) {
Expand All @@ -62,8 +62,11 @@ impl NodeVisitor for StaticPathParser {
(Some(ParseToken::Absolute), ParseToken::In)
| (Some(ParseToken::Absolute), ParseToken::Array)
| (Some(ParseToken::Array), ParseToken::Key(_))
| (Some(ParseToken::Array), ParseToken::KeyString(_))
| (Some(ParseToken::Key(_)), ParseToken::In)
| (Some(ParseToken::KeyString(_)), ParseToken::In)
| (Some(ParseToken::Key(_)), ParseToken::Array)
| (Some(ParseToken::KeyString(_)), ParseToken::Array)
| (Some(ParseToken::ArrayEof), ParseToken::Array)
| (Some(ParseToken::Array), ParseToken::Number(_))
| (Some(ParseToken::ArrayEof), ParseToken::In) => VisitStatus::PartialValid,
Expand All @@ -77,7 +80,14 @@ impl NodeVisitor for StaticPathParser {
(Some(ParseToken::In), ParseToken::Key(key))
| (Some(ParseToken::Key(key)), ParseToken::ArrayEof) => {
self.static_path_elements
.push(StaticPathElement::ObjectKey(key.clone()));
.push(StaticPathElement::ObjectKey(key.to_string()));
VisitStatus::Valid
}

(Some(ParseToken::In), ParseToken::KeyString(key))
| (Some(ParseToken::KeyString(key)), ParseToken::ArrayEof) => {
self.static_path_elements
.push(StaticPathElement::ObjectKey(key.to_string()));
VisitStatus::Valid
}

Expand Down
15 changes: 7 additions & 8 deletions src/redisjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,15 @@ impl RedisJSON {
Ok(res)
} else {
// Adding somewhere in existing object, use jsonpath_lib::replace_with
let p = parsed_static_path
.static_path_elements
.iter()
.map(|e| e.to_string())
.collect::<Vec<_>>()
.join("");
let mut set = false;
let mut selector = SelectorMut::default();
if let Err(e) = selector.str_path(
&parsed_static_path
.static_path_elements
.iter()
.map(|e| e.to_string())
.collect::<Vec<String>>()
.join(""),
) {
if let Err(e) = selector.str_path(&p) {
return Err(e.into());
}
selector.value(&mut self.data);
Expand Down