livioribeiro/rusted-cypher

working with NULL

flosse opened this issue · 5 comments

Cypher does not allow to use null as parameter type. Unfortunately a serialized struct with a Option<T> field contains null values.
So e.g. this would fail:

struct Foo {
  id:  Option<u32>,
  name: String
}
let x = Foo{id: None, name: "foo".to_string()};
graph.cypher()
  .exec(cypher_stmt!("CREATE (e:Entry {entry}) RETURN e.id" {
  "entry" => &x }))

Do you have a recommendation for handling such a case?

It seems that the query is causing neo4j to throw an exception.

Logging shows that the query sent is:

{
    "statements": [
        {
            "statement": "CREATE (n:Entry {entry}) return n.id",
            "parameters": {
                "entry": {
                    "id": null,
                    "name": "foo"
                }
            }
        }
    ]
}

This may be a problem with neo4j itself, I'll try to find out something about this and maybe file an issue on neo4j repo.

Thanks.

This may be a problem with neo4j itself

actually it's a feature ;-) So neo4j won't change the behavior! So the current solution is to either check it in the cypher statement or to resolve the Option value manually by using my_val.unwrap_or("".to_string())
I think rusted_cypher can't help there, so I'll close this issue.

I was about to answer about that 😄

BTW: If you're using the SET statement you don't have this problem :)

I hope they fix that feature :)