Developers using Neo4j are currently working alone when they should be working together, but they don’t know who is working on the same technologies. This graph aims to solve this by linking developers with similar interests, projects and events.
This gist was prompted by Nigel Small’s tweet of a query to generate a unique id for a node (and is posted here with his agreement). It inspired me to think about how it could be used in a full example, unrestricted by Twitter’s 140 characters. I have also looked at how we could generate different sets of unique ids for different labels.
Auto-incrementing #Neo4j counter
MERGE (x:Counter {name:'foo'})
ON CREATE SET x.count = 0
ON MATCH SET x.count = x.count + 1
RETURN x.count
— Nigel Small (@technige) December 16, 2013
Here is an example of importing distinct data from a CSV file, and creating relationships using that data.
This method is more efficient than just using MERGE. It never tries to match any duplicates from the csv file as they are filtered out beforehand. It still uses MERGE to ensure that duplicate nodes are not created, but in this situation this would only be required if the csv file was loaded more than once.
private void ClearDb(IGraphClient client) | |
{ | |
client.Cypher | |
.Match("(n)") | |
.DetachDelete("n") | |
.ExecuteWithoutResults(); | |
} |
IF exists( select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='myTable' and COLUMN_NAME='columnToDrop') | |
BEGIN | |
ALTER TABLE myTable drop COLUMN columnToDrop | |
END |
ALTER TABLE [dbo].[MyTable] | |
ADD CONSTRAINT FK_MyTable_OtherTable FOREIGN KEY (OType) | |
REFERENCES [dbo].[OtherTable] (Ident) | |
ON DELETE CASCADE | |
ON UPDATE CASCADE |
It doesn’t seem to, and the way it is supposed to work causes an error (see query 4) This is based upon this blog post: http://blog.neo4j.org/2013/11/neo4j-200-rc1-final-preparations.html