简体   繁体   中英

Can I parameterize labels and properties on CREATE or SET? (REST and transaction)

I have a query

1. CREATE (a:%1$s {props}), (b:%2$s {props2}), (b)-[:%3$s {relProps}]->(a)
2. MATCH (a:%1$s { value:{value} })-[:%2$s]->(b) WHERE (b:%3$s) SET (b {props})

I'm using underscore.string to allow string format but would love to just stick with parameters.

Is it possible to parameterize labels such as

{ 
  "query": CREATE (a:{label} {props}),
  "params": {
    "label":"SomeLabel",
    "props":{....}
  }
}

and is it also possible to parameterize properties on a SET?

{
  "query": "MATCH ..... SET (node {props})"
  "params": {
    "props":{
      "prop1:":"Property Name",
      .... 
    }
  }
}

Also is there a way to parameterize on a "MERGE"? it gives me 'Parameter maps cannot be used in MERGE patterns (use a literal map instead, eg. "{id: {param}.id}")'

EDIT: what about parameterizing where clause?

MATCH (:Identity%1$s {nodeId:{nodeId})-[r*2..3]-(node1)-[b:%2$s]->(node2) %4$s return *

I have %4$s there for me to put whatever clauses I need to. If I want to have it as

WHERE node1.nodeId= {someNodeId} SET b= {props}

is that possible??

Also when I'm doing a transaction SET node={props} does not seem to work. I tried

statements:[
  {
    "statement":"..... SET node={props}",
    "parameters":{
      "props": {
        "description":"some description"
      }
    }
  }
]

Any suggestions?? Thank you!

You cannot parameterize labels since the query plan might look different for a different label.

Parameterizing multiple properties using a map is possible, note the slight difference in the SET syntax:

{
  "query": "MATCH ..... SET node = {props}"
  "params": {
    "props":{
      "prop1:":"Property Name",
      .... 
    }
  }
}

Not 100% about MERGE but I guess this should work:

{
  "query": "MERGE (n:Label {identifier: {idValue}) ON CREATE SET n = {props}"
  "params": {
    "identifier": 123,
    "props":{
      "identifier": 123,
      "prop1:":"Property Name",
      .... 
    }
  }
}

I found out!

CREATE  ...  SET node = {props}

does the trick to set multiple properties with parameters

doc: http://docs.neo4j.org/chunked/snapshot/cypher-parameters.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM