Modeling Node Graphs
Each node in Neo4j has a set of unique labels, properties and can have any number of incoming and outgoing relationships (or none).
In order to present the contents of a node graph as a SQL database, the connector models node labels and relationships as read-only views.
Node labels are Neo4j's primary method for categorizing nodes, so they have been adapted into SQL views. Each node label is exposed as an individual view.
For example, the following query displays all nodes that contain a "Product" label:
SELECT * FROM Product
Note that, because nodes can have multiple labels, certain nodes appear in several label views.
The connector models each novel combination of the following as a view.
- Source node label
- Destination node label
- Relationship type (name)
The view associated with that combination takes the form of SourceName_RelationshipType_DestinationName.
For example, if there is at least one node with the label "Product" which has the relationship "Part_Of" with a node with the label "Category", you can query this relationship as follows:
SELECT * FROM Product_Part__Of_Category
Since the source and destination labels of the relationship denote its direction, bidirectional relationships are modeled as two views: A_RelationshipType_B and B_RelationshipType_A, where A and B represent unique node labels.
Note that, because nodes can have multiple relationships, certain nodes appear in several relationship views.
Properties are modeled as columns.
Node PropertiesIn nodes label views, properties are inherited from the nodes containing the node label, keeping their original names.
Relationship PropertiesIn relationship views, properties are inherited from the all instances of the source node, the destination node, and the relationship itself.
The following columns are exposed:
- A source_<PropertyName> column for each property in the instances of the source node.
- A destination_<PropertyName> column for each property in the instances of the destination node.
- A relationship_<PropertyName> column for each property in the instances of the relationship.