-
Notifications
You must be signed in to change notification settings - Fork 79
Description
Right now as I see it there is no ability to grab a custom map from the output. This is important when aggregating results using something like collect. Specifically, I have code that collects three nodes into a map as below:
MATCH (n:Model)
OPTIONAL MATCH (n)-[:LeftLink]->(d_left)
OPTIONAL MATCH (n)-[:RightLink]->(d_right)
RETURN collect({{ node:n, d_left:d_left, d_right:d_right }}) as res;
This result in res being a BoltList of BoltMaps. Unfortunately because BoltMap isnt exposed, I cannot unpack this with something like let maps = row.get::<Vec<BoltMap>>("res").unwrap(); and because Row does not implement From<BoltType> I cannot use Row either.
I have made local changes that include a new exposed type call Map that wraps BoltMap and a exposes a single get method to allow users to use arbitrary output from the graph.
// row.rs
/// A map very similar to a `HashMap` that implements `TryFrom<BoltType>` to allow for retrieval.
#[derive(Debug)]
pub struct Map {
inner: BoltMap,
}
impl Map {
pub fn new(inner: BoltMap) -> Self {
Map { inner }
}
pub fn get<T: std::convert::TryFrom<BoltType>>(&self, key: &str) -> Option<T> {
self.inner.get(key)
}
}// convert.rs
impl TryFrom<BoltType> for Map {
type Error = Error;
fn try_from(input: BoltType) -> Result<Map> {
match input {
BoltType::Map(n) => Ok(Map::new(n)),
_ => Err(Error::ConversionError),
}
}
}If these changes seem reasonable I can create a pull request, or really any feedback on this would be appreciated. Maybe I am missing something already available to do this. Thanks!