Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/server/database/graph_db/agensgraph/models/edge.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ def to_cypher_create(self) -> tuple[str, tuple]:
# Build property string with %s placeholders
props = ", ".join([f"{k}: %s" for k in properties.keys()])

# Determine the relationship pattern based on direction
# Double-quote the relation type to handle reserved Cypher keywords (e.g. REFERENCES)
quoted_rel = f'"{self.relation}"'
if self.direction == "->":
rel_pattern = f"(a)-[r:{self.relation} {{ {props} }}]->(b)"
rel_pattern = f"(a)-[r:{quoted_rel} {{ {props} }}]->(b)"
elif self.direction == "<-":
rel_pattern = f"(a)<-[r:{self.relation} {{ {props} }}]-(b)"
rel_pattern = f"(a)<-[r:{quoted_rel} {{ {props} }}]-(b)"
else: # undirected
rel_pattern = f"(a)-[r:{self.relation} {{ {props} }}]-(b)"
rel_pattern = f"(a)-[r:{quoted_rel} {{ {props} }}]-(b)"

# Build the query to check node existence and create relationship
query = f"MATCH (a {{id: %s}}), (b {{id: %s}}) CREATE {rel_pattern} RETURN r"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_to_cypher_create(self):

# Check the parameterized query format (uses %s placeholders)
assert "MATCH (a {id: %s}), (b {id: %s})" in query
assert "CREATE (a)-[r:RELATES_TO { since: %s, active: %s, id: %s }]->(b)" in query
assert 'CREATE (a)-[r:"RELATES_TO" { since: %s, active: %s, id: %s }]->(b)' in query
assert "RETURN r" in query

# Check parameters (tuple format: source_id, target_id, then property values)
Expand Down
Loading