Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
  • Loading branch information
MAVRICK-1 authored Feb 5, 2024
1 parent cc74085 commit 7e1b920
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions iyp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,27 @@ def add_links(self, src_node, links):

self.tx.run(matches + where + merges).consume()
self.commit()

def add_relationship_properties(
self,
node_label_properties,
relationship,
connected_node_label_properties,
properties):
"""The function goes through each provided property and adds it to the
relationship between the specified nodes, but only if that property doesn't
already exist in the relationship."""
property_setters = ','.join([f'rel.{prop} = ${{props}}.${{prop}}' for prop in properties.keys()])
add_query = f"""
MATCH (node1:{node_label_properties})-[rel:{relationship}]-(node2:{connected_node_label_properties})
WITH rel
UNWIND keys($properties) AS prop
WHERE NOT EXISTS(rel[prop])
SET {property_setters}
"""
res = self.tx.run(add_query, properties=properties)
res.consume()
self.commit()

def batch_add_properties(self, id_prop_list):
"""Add properties to existing nodes.
Expand All @@ -579,32 +600,7 @@ def batch_add_properties(self, id_prop_list):
res = self.tx.run(add_query, batch=batch)
res.consume()
self.commit()


# Function to execute the Cypher query to set properties on relationships
def add_relationship_properties(
self,
node_label_properties,
relationship,
connected_node_label_properties,
properties):
"""
The function goes through each provided property and adds it to the relationship
between the specified nodes, but only if that property doesn't already
exist in the relationship.
"""
property_setters = ", ".join([f"rel.{prop} = ${{props}}.${{prop}}" for prop in properties.keys()])
add_query = f"""
MATCH (node1:{node_label_properties})-[rel:{relationship}]-(node2:{connected_node_label_properties})
WITH rel
UNWIND keys($properties) AS prop
WHERE NOT EXISTS(rel[prop])
SET {property_setters}
"""

res = self.tx.run(add_query,properties=properties)
res.consume()
self.commit()


class BasePostProcess(object):
Expand Down

0 comments on commit 7e1b920

Please sign in to comment.