Skip to content

Commit d06eefe

Browse files
committed
Cypher: Test whether endpoints exist before running inserts
1 parent 1bf458e commit d06eefe

8 files changed

+32
-1
lines changed

cypher/queries/interactive-update-1.cypher

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
OPTIONAL MATCH (c:City {id: $cityId})
2+
WITH 1/count(c) AS testWhetherCityFound
13
MATCH (c:City {id: $cityId})
24
CREATE (p:Person {
35
id: $personId,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
OPTIONAL MATCH (person:Person {id: $personId}), (post:Post {id: $postId})
2+
WITH 1/count(person) AS testWhetherPersonFound, 1/count(post) AS testWhetherPostFound
13
MATCH (person:Person {id: $personId}), (post:Post {id: $postId})
24
CREATE (person)-[:LIKES {creationDate: $creationDate}]->(post)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
OPTIONAL MATCH (person:Person {id: $personId}), (comment:Comment {id: $commentId})
2+
WITH 1/count(person) AS testWhetherPersonFound, 1/count(comment) AS testWhetherCommentFound
13
MATCH (person:Person {id: $personId}), (comment:Comment {id: $commentId})
24
CREATE (person)-[:LIKES {creationDate: $creationDate}]->(comment)

cypher/queries/interactive-update-4.cypher

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
OPTIONAL MATCH (p:Person {id: $moderatorPersonId})
2+
WITH 1/count(p) AS testWhetherPersonFound
13
MATCH (p:Person {id: $moderatorPersonId})
24
CREATE (f:Forum {id: $forumId, title: $forumTitle, creationDate: $creationDate})-[:HAS_MODERATOR]->(p)
35
WITH f
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
OPTIONAL MATCH (f:Forum {id: $forumId}), (p:Person {id: $personId})
2+
WITH 1/count(f) AS testWhetherForumFound, 1/count(p) AS testWhetherPersonFound
13
MATCH (f:Forum {id: $forumId}), (p:Person {id: $personId})
24
CREATE (f)-[:HAS_MEMBER {creationDate: $creationDate}]->(p)

cypher/queries/interactive-update-6.cypher

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
1-
MATCH (author:Person {id: $authorPersonId}), (country:Country {id: $countryId}), (forum:Forum {id: $forumId})
1+
OPTIONAL MATCH
2+
(author:Person {id: $authorPersonId}),
3+
(country:Country {id: $countryId}),
4+
(forum:Forum {id: $forumId})
5+
WITH
6+
1/count(author) AS testWhetherAuthorFound,
7+
1/count(country) AS testWhetherCountryFound,
8+
1/count(forum) AS testWhetherForumFound
9+
MATCH
10+
(author:Person {id: $authorPersonId}),
11+
(country:Country {id: $countryId}),
12+
(forum:Forum {id: $forumId})
213
CREATE (author)<-[:HAS_CREATOR]-(p:Post:Message {
314
id: $postId,
415
creationDate: $creationDate,

cypher/queries/interactive-update-7.cypher

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
OPTIONAL MATCH
2+
(author:Person {id: $authorPersonId}),
3+
(country:Country {id: $countryId}),
4+
(message:Message {id: $replyToPostId + $replyToCommentId})
5+
WITH
6+
1/count(author) AS testWhetherAuthorFound,
7+
1/count(country) AS testWhetherCountryFound,
8+
1/count(message) AS testWhetherMessageFound
19
MATCH
210
(author:Person {id: $authorPersonId}),
311
(country:Country {id: $countryId}),
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
OPTIONAL MATCH (p1:Person {id: $person1Id}), (p2:Person {id: $person2Id})
2+
WITH 1/count(p1) AS testWhetherP1Found, 1/count(p2) AS testWhetherP2Found
13
MATCH (p1:Person {id: $person1Id}), (p2:Person {id: $person2Id})
24
CREATE (p1)-[:KNOWS {creationDate: $creationDate}]->(p2)

0 commit comments

Comments
 (0)