0
votes

Given a string containing a Neo4j cypher query, how to determine quickly in python it is db read or db write.

Currently I have thought of two ways of seeing this -

  1. Check for keywords like CREATE, DELETE etc to tag write queries and
    MATCH, START etc to tag read queries.
  2. Otherwise we can check for patterns according to this link here- Neo4j refcard and write a parser for it accordingly.

Method 1 fails here -

MATCH (n:Person {id:1, create:3}) return n

And method 2 looks too deep for seemingly small task.

Any other/better ideas to do the same?

1
You can modify method 1 to check if the keyword is outside any brackets.Anmol Singh Jaggi

1 Answers

2
votes

You can use EXPLAIN option and inspect operatorType of the execution plan:

EXPLAIN MERGE (n:Person)

and find and check for possible values for writing, updating and other, something like that

"operatorType": "MergeCreateNode"
"operatorType": "CreateNode"
"operatorType": "MergeCreateRelationship"