diff --git a/apps/db-adapter/internal/memgraph/queries.go b/apps/db-adapter/internal/memgraph/queries.go index 9766072..d85b24f 100644 --- a/apps/db-adapter/internal/memgraph/queries.go +++ b/apps/db-adapter/internal/memgraph/queries.go @@ -59,15 +59,11 @@ var HardDeletePersonCypherQuery string //go:embed queries/get_relationship.cypher var GetRelationshipCypherQuery string -// Requires id1, id2, Relationship parameters. +// Requires childId, parentId, childRelationship, parentRelationship parameters. +// returns relationships // -//go:embed queries/create_directed_relationship.cypher -var CreateDirectedRelationshipCypherQuery string - -// Requires id1, id2, Relationship1, Relationship2 parameters. -// -//go:embed queries/create_two_directed_relationships.cypher -var CreateTwoDirectedRelationshipCypherQuery string +//go:embed queries/create_child_parent_relationships.cypher +var CreateChildParentRelationshipCypherQuery string // Requires id parameter. // diff --git a/apps/db-adapter/internal/memgraph/queries/create_child_parent_relationships.cypher b/apps/db-adapter/internal/memgraph/queries/create_child_parent_relationships.cypher new file mode 100644 index 0000000..4958c4a --- /dev/null +++ b/apps/db-adapter/internal/memgraph/queries/create_child_parent_relationships.cypher @@ -0,0 +1,6 @@ +MATCH (a:Person), (b:Person) +WHERE id(a) = $childId AND id(b) = $parentId AND $parentId != $childId +MERGE (a)-[r1:Child]->(b)-[r2:Parent]->(a) +ON CREATE SET r1 = $childRelationship +ON CREATE SET r2 = $parentRelationship +RETURN collect(r1)+collect(r2) as relationships; \ No newline at end of file diff --git a/apps/db-adapter/internal/memgraph/queries/create_directed_relationship.cypher b/apps/db-adapter/internal/memgraph/queries/create_directed_relationship.cypher deleted file mode 100644 index d847828..0000000 --- a/apps/db-adapter/internal/memgraph/queries/create_directed_relationship.cypher +++ /dev/null @@ -1,5 +0,0 @@ -MATCH (a:Person) -OPTIONAL MATCH (b:Person) -WHERE id(a) = $id1 AND id(b) = $id2 -CREATE (a)-[r:Relationship $Relationship]->(b) -RETURN r AS relationship; \ No newline at end of file diff --git a/apps/db-adapter/internal/memgraph/queries/create_relationship.cypher b/apps/db-adapter/internal/memgraph/queries/create_relationship.cypher deleted file mode 100644 index 20f8f25..0000000 --- a/apps/db-adapter/internal/memgraph/queries/create_relationship.cypher +++ /dev/null @@ -1,4 +0,0 @@ -MATCH (a:Person), (b:Person) -WHERE id(a) = $id1 AND id(b) = $id2 -CREATE (a)-[r:Relationship $Relationship]-(b) -RETURN r as relationship \ No newline at end of file diff --git a/apps/db-adapter/internal/memgraph/queries/create_sibling_relationship.cypher b/apps/db-adapter/internal/memgraph/queries/create_sibling_relationship.cypher new file mode 100644 index 0000000..cd3c2a6 --- /dev/null +++ b/apps/db-adapter/internal/memgraph/queries/create_sibling_relationship.cypher @@ -0,0 +1,6 @@ +MATCH (a:Person), (b:Person) +WHERE id(a) = $id1 AND id(b) = $id2 AND $id1 != $id2 +MERGE (a)-[r1:Sibling]->(b)-[r2:Sibling]->(a) +ON CREATE SET r1 = $Relationship1 +ON CREATE SET r2 = $Relationship2 +RETURN collect(r1)+collect(r2) as relationships; \ No newline at end of file diff --git a/apps/db-adapter/internal/memgraph/queries/create_sibling_relationships_based_on_parent.cypher b/apps/db-adapter/internal/memgraph/queries/create_sibling_relationships_based_on_parent.cypher new file mode 100644 index 0000000..8a54c56 --- /dev/null +++ b/apps/db-adapter/internal/memgraph/queries/create_sibling_relationships_based_on_parent.cypher @@ -0,0 +1,4 @@ +MATCH (a:Person)-[:Parent]->(b:Person)-[:Child]->(c:Person) +WHERE id(a) = $childId AND id(b) = $parentId AND $parentId != $childId AND id(c) != id(a) +MERGE (a)-[r1:Sibling]->(c)-[r2:Sibling]->(a) +RETURN collect(r1)+collect(r2) as relationships; \ No newline at end of file diff --git a/apps/db-adapter/internal/memgraph/queries/create_spouse_relationship.cypher b/apps/db-adapter/internal/memgraph/queries/create_spouse_relationship.cypher new file mode 100644 index 0000000..093a8aa --- /dev/null +++ b/apps/db-adapter/internal/memgraph/queries/create_spouse_relationship.cypher @@ -0,0 +1,6 @@ +MATCH (a:Person), (b:Person) +WHERE id(a) = $id1 AND id(b) = $id2 AND $id1 != $id2 +MERGE (a)-[r1:Spouse]->(b)-[r2:Spouse]->(a) +ON CREATE SET r1 = $Relationship1 +ON CREATE SET r2 = $Relationship2 +RETURN collect(r1)+collect(r2) as relationships; \ No newline at end of file diff --git a/apps/db-adapter/internal/memgraph/queries/create_two_directed_relationships.cypher b/apps/db-adapter/internal/memgraph/queries/create_two_directed_relationships.cypher deleted file mode 100644 index ec215c2..0000000 --- a/apps/db-adapter/internal/memgraph/queries/create_two_directed_relationships.cypher +++ /dev/null @@ -1,5 +0,0 @@ -MATCH (a:Person), (b:Person) -WHERE id(a) = $id1 AND id(b) = $id2 -CREATE (a)-[r1:Relationship $Relationship1]->(b) -CREATE (b)-[r2:Relationship $Relationship2]->(a) -RETURN r1 as relationship1, r2 as relationship2 \ No newline at end of file