john
john

Reputation: 11

Generate Cypher Query from Visual model

I am looking if there is a way (maybe using a library or if neo4j supports this), to generate a Cypher query from a Visual Model of a query.

This is what I mean, I may have a visual query (which I am creating myself say using zoomcharts) in my app which looks like this:

screnshot

This query looks for all persons who live in city Vienna.

Of course I can get list of nodes and their relationships say as JSON data out of this visual model.

What I want is from this to generate a Cypher query (out of this visual model and say the JSON data I generate from the visual model).

Do you know if there is a tool or library (or maybe it is supported by neo4j in some way) to help me achieve this?


IMHO my question is similar to this one, however that one is 4 years old and doesn't contain much helpful info.

Upvotes: 1

Views: 1002

Answers (2)

stdob--
stdob--

Reputation: 29147

Such a query can be represented as a sequence of matches for nodes and relationships:

MATCH (N0:`Person`)
MATCH (N1:`City` {`name`:"Vienna"})
MATCH (N0)-[R0:`lives in`]->(N1)
RETURN *

And this can easily be built from JSON:

const nodesMatch = []
graph.nodes.forEach(function(n) {
  const nodeVar = 'N' + n.id
  const nodeLabels = '`' + n.labels.join(':') + '`'
  nodesMatch.push(
    'MATCH (' + nodeVar + ':' + nodeLabels + ')'
  )
})

[ https://jsfiddle.net/mx9hmdq4/ ]

P.S. I also recommend that you pay attention to popoto:

Visual query builder for Neo4j graph database - https://github.com/Nhogs/popoto

Upvotes: 2

Christophe Willemsen
Christophe Willemsen

Reputation: 20185

If you use arrows to create your visual model, you can export it to Cypher :

http://www.apcjones.com/arrows/#

enter image description here

Upvotes: 2

Related Questions