Wolfgang-Schuetzelhofer / jcypher

Java access to Neo4J graph databases at multiple levels of abstraction
Apache License 2.0
86 stars 15 forks source link

Replace all node properties for the new ones #34

Closed jknack closed 6 years ago

jknack commented 7 years ago

Hi,

I would like to do this:

MATCH (n)
WHERE n.name = "Rik"
SET n = {plays: "Piano", age: 23}

But I can't figure it out how to do it with jcypher. Appreciate any help.

Thanks

Wolfgang-Schuetzelhofer commented 7 years ago

Hi, the following code snippet should do:

IClause[] clauses; JcQuery query; String cypher;

    JcNode n = new JcNode("n");

    clauses = new IClause[]{
            MATCH.node(n),
            WHERE.valueOf(n.property("name")).EQUALS("RIK"),
            DO.SET(n.property("plays")).to("piano"),
            DO.SET(n.property("age")).to(23)
    };
    query = new JcQuery();
    query.setClauses(clauses);
    cypher = print(clauses, Format.PRETTY_1);
    System.out.println(cypher);

Best regards

jknack commented 7 years ago

Hi @Wolfgang-Schuetzelhofer,

I wasn't clear enough, my bad. Suppose I don't know exactly what properties are going to be updated, just got a map and want to:

  1. reset/clear any existing properties
  2. set/save the current state

This is supported by neo4j but don't see how to do it in jcypher

Wolfgang-Schuetzelhofer commented 7 years ago

Hi Edgar, you can do the following: JcNode n = new JcNode("n");

clauses = new IClause[]{
        MATCH.node(n),
        WHERE.valueOf(n.property("name")).EQUALS("RIK"),
        NATIVE.cypher("SET n = {plays: \"Piano\", age: 23}")
};

You can use the NATIVE clause whenever you want to express CYPHER that's not currently supported by JCypher. You can express arbitrary parts of a query using the NATIVE clause.

I hope that helps, best regards, Wolfgang

jknack commented 7 years ago

It does, thank you.

yaoleo commented 6 years ago

i think this should be in the doc