Neo4j GraphDB Connection | How to invoke Delegate

Dear Devs, Dear Community & fellow Travellers,

I am currently working on a vvvv - Neo4j connector and Statement Library / Generator.
Neo4j is a Graph Database provider an i believe that there are endless application possibilities when used in vvvv gamma. Check out their website and docs if you haven’t already, even a noob like me could grasp the basic concepts of the query language “Cypher” in a couple of hours. https://neo4j.com

It comes with a c# driver on nuget.org which is easy peasy to integrate: [NuGet Gallery | Neo4j.Driver 4.3.2](Neo4j Nuget)

Neo4j .NET https://neo4j.com/docs/pdf/neo4j-driver-manual-1.7-dotnet.pdf

I currently run a neo4j instance on aws ec2 and have already successfully established connection out of vvvv gamma. There are three types of transactions you can perform which are:

  • Auto Commit Transactions
  • Transaction Functions
  • Explicit Transactions

I managed to get an Auto Commit Transaction going by following the example code:

public void AddPerson(string name) {
using (var session = Driver.Session()) 
{
session.Run("CREATE (a:Person {name: $name})", new {name});
}
}

and translating it into this:
Auto%20Commit%20Transaction

I am now trying to use Transaction Functions as they provide more functionality and allow more complex Cipher statements.

The code example for this is the following:

public void AddPerson(string name)
{
using (var session = Driver.Session())
{
session.WriteTransaction(tx => tx.Run("CREATE (a:Person {name: $name})", new {name}));
}
}

I figuered that this would include delegates and i tinkered around a little but am stuck.
This is how far i came:

I tried different delegates/different output counts/ also the System Func`1 stuff, nothing works.
Is the delegate approach even correct? What am I doing worng?

Any help would be highly appreciated and i am looking forward to build some Cypher Statement helpers that would make live easier by the power of vvvv gamma!

Thank you for your time!
J

it looks correct, but you don’t need to invoke the delegate yourself, the WriteTransaction seems to do that for you. so directly connect the delegate to it’s input.

image

the easiest way is to start a link at the input for the delegate and then press middle click to create the delegate.

There are different overlaods of the WriteTransaction method: https://neo4j.com/docs/api/dotnet-driver/current/html/59a1b235-df88-74f2-bc9f-517c2df405d8.htm
you might need to chose another one that has the delegate input. in order to do that, double click the write WriteTransaction node and add the delegate input pin to the selection.

Hi Tonfilm,
Thanks! That helped a lot ! In addition I had to use Run(IStatementRunner) instead of Run(ISession) as the first one inherits from ITransaction.
Function%20Transaction
Now multiple statements are transmitted without a problem.
Hope to see you at Schmiede!
Best,
J

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.