Skip to content

Commit

Permalink
Path support
Browse files Browse the repository at this point in the history
  • Loading branch information
Threated committed Jun 12, 2022
1 parent 282fc06 commit 1f71902
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
29 changes: 23 additions & 6 deletions src/parse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, ops::{Deref, DerefMut, Index}};
use std::{collections::HashMap, ops::{Deref, DerefMut}};
use indexmap::IndexMap;
use redis::{Value, RedisResult, FromRedisValue, from_redis_value};

Expand Down Expand Up @@ -26,14 +26,14 @@ pub enum GraphValue {
Unknown(Value),
Map(GraphMap),
Point(GeoPoint),
Path(Value),
Node(Value),
Path(GraphMap),
Node(Node),
Array(Vec<GraphValue>),
Integer(i64),
Double(f64),
String(String),
Boolean(bool),
Relation(Value),
Relation(Relationship),
Null,
}

Expand Down Expand Up @@ -69,7 +69,7 @@ impl DerefMut for GraphMap {
}

/// Node Type
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Node {
/// Redisgraph internal node id
pub id: i64,
Expand All @@ -90,7 +90,7 @@ impl Node {
}

/// Relationship Type
#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq)]
pub struct Relationship {
/// Redisgraph internal relationship id
pub id: i64,
Expand Down Expand Up @@ -157,6 +157,22 @@ impl PropertyAccess for Relationship {
}
}

#[derive(Debug, PartialEq, Clone)]
struct GraphPath {
pub nodes: Vec<Node>,
pub relationships: Vec<Relationship>
}

impl FromRedisValue for GraphPath {
fn from_redis_value(v: &Value) -> RedisResult<Self> {
let (nodes, relationships): (Vec<Node>, Vec<Relationship>) = from_redis_value(v)?;
Ok(GraphPath {
nodes,
relationships
})
}
}


pub trait FromGraphValue: Sized {
fn from_graph_value(value: &GraphValue) -> RedisResult<Self>;
Expand Down Expand Up @@ -397,6 +413,7 @@ fn convert_to_graphvalue(type_: i64, val: &Value) -> RedisResult<GraphValue> {
match type_ {
VALUE_NODE => Ok(GraphValue::Node(from_redis_value(val)?)),
VALUE_EDGE => Ok(GraphValue::Relation(from_redis_value(val)?)),
VALUE_PATH => Ok(GraphValue::Map(from_redis_value(val)?)),
VALUE_MAP => Ok(GraphValue::Map(from_redis_value(val)?)),
VALUE_POINT => Ok(GraphValue::Point(from_redis_value(val)?)),
VALUE_NULL => Ok(GraphValue::Null),
Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use paste::paste;
use indexmap::indexmap;
use crate::{query, GraphQuery, GraphCommands, GraphValue, Node, PropertyAccess, GraphMap, GeoPoint};
use crate::{query, GraphQuery, GraphCommands, GraphValue, Node, GraphMap, GeoPoint};

#[test]
fn test_query_macro() {
Expand Down

0 comments on commit 1f71902

Please sign in to comment.