Skip to content

Instantly share code, notes, and snippets.

@apcj
Created April 25, 2016 15:26
Show Gist options
  • Save apcj/3851e64d5dae640ac4f2bb6123b56488 to your computer and use it in GitHub Desktop.
Save apcj/3851e64d5dae640ac4f2bb6123b56488 to your computer and use it in GitHub Desktop.
MERGE (person:Person{name:"Alistair"})
MERGE (role:Role{name:"Software Engineer"})
MERGE (company:Company{name:"Neo Technology"})
CREATE (empl:Employment{from: 2011})
MERGE (person)-[:CURRENT]->(empl)
MERGE (empl)-[:WORKS_AT]->(company)
MERGE (empl)-[:ROLE]->(role)
// Determine whether first story already exists
WITH empl, person,
CASE WHEN ((person)-[:FIRST]->()) THEN [] ELSE ["blalba"]
END
AS firstNotExists
// Create FIRST rel newStory is first story
FOREACH (i IN firstNotExists | MERGE (person)-[:FIRST]->(empl))
WITH empl, person
// Delete old LAST relationship
MATCH (empl)<-[:CURRENT]-(person)-[oldCurrent:CURRENT]->(oldEmployment)
DELETE oldCurrent
MERGE (oldEmployment)-[:NEXT]->(empl)
SET oldEmployment.to = empl.from;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment