Skip to content

Instantly share code, notes, and snippets.

@bkimble
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save bkimble/eec1992851991ea2e9c8 to your computer and use it in GitHub Desktop.

Select an option

Save bkimble/eec1992851991ea2e9c8 to your computer and use it in GitHub Desktop.

Revisions

  1. bkimble revised this gist Nov 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.sql
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ LIMIT 1
    MERGE (u:User {id: 3})

    // this is the part I am not sure how to do
    (IF NOT FOUND)
    (IF c1 WAS NOT FOUND)
    CREATE (c:Contact)
    (END)

  2. bkimble revised this gist Nov 20, 2014. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions gistfile1.sql
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,7 @@ LIMIT 1
    // Create or make user based on ID
    MERGE (u:User {id: 3})

    // this is the part I am not sure how to do
    (IF NOT FOUND)
    CREATE (c:Contact)
    (END)
  3. bkimble created this gist Nov 20, 2014.
    25 changes: 25 additions & 0 deletions gistfile1.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    // Try to find a contact that is connected to a node
    // with an email addrss of bob@google.com or jerk@hello.com
    // Pick the first one (there should never be multiple contacts with the same emails)
    // but just in case, pick the first found)
    MATCH (e1:Email)-[:EMAIL]-(c1:Contact)
    WHERE (e1.address IN ['[email protected]','[email protected]'])
    WITH e1,c1
    LIMIT 1
    // Create or make user based on ID
    MERGE (u:User {id: 3})

    (IF NOT FOUND)
    CREATE (c:Contact)
    (END)

    CREATE (u)-[:KNOWS]->(c)

    FOREACH(email in ["[email protected]",'[email protected]'] |
    MERGE (e:Email {address:email})
    MERGE (c)-[:EMAIL]-(e)
    )

    MERGE (a:Alias {name: "Jack"})
    MERGE (c)-[:ALIAS]-(a);