Add support for Bolt v4(.1) (#10)

* Added handshake support
* Add support for v4 hello and goodbye
* Add support for pulling n results
* Add support for transactions
* Add pull n for the dump
* Add support for NOOP
* Add support for multiple queries
* Update bolt session to support qid
* Update drivers test with multiple versions and go
* Extract failure handling into a function
* Use unique ptr instead of optional for query execution
* Destroy stream before query execution

Co-authored-by: Antonio Andelic <antonio.andelic@memgraph.io>
This commit is contained in:
antonio2368
2020-10-16 12:49:33 +02:00
committed by GitHub
parent 42ac5d4ea3
commit 0bcc1d67bc
58 changed files with 2878 additions and 500 deletions

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Neo4j.Driver.Simple" Version="4.1.1" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,20 @@
using System;
using System.Linq;
using Neo4j.Driver;
public class Basic {
public static void Main(string[] args) {
using(var driver = GraphDatabase.Driver("bolt://localhost:7687", AuthTokens.None, (ConfigBuilder builder) => builder.WithEncryptionLevel(EncryptionLevel.None)))
using(var session = driver.Session())
{
session.Run("MATCH (n) DETACH DELETE n").Consume();
session.Run("CREATE (alice:Person {name: \"Alice\", age: 22})").Consume();
var result = session.Run("MATCH (n) RETURN n").First();
var alice = (INode) result["n"];
Console.WriteLine(alice["name"]);
Console.WriteLine(string.Join(", ", alice.Labels));
Console.WriteLine(alice["age"]);
}
Console.WriteLine("All ok!");
}
}

View File

@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Neo4j.Driver;
public class Transactions
{
public static void Main(string[] args) {
using(var driver = GraphDatabase.Driver("bolt://localhost:7687", AuthTokens.None, (builder) => builder.WithEncryptionLevel(EncryptionLevel.None)))
{
ClearDatabase(driver);
// Wrong query.
try
{
using(var session = driver.Session())
using(var tx = session.BeginTransaction())
{
CreatePerson(tx, "mirko");
// Incorrectly start CREATE
tx.Run("CREATE (").Consume();
CreatePerson(tx, "slavko");
tx.Commit();
}
}
catch (ClientException)
{
Console.WriteLine("Rolled back transaction");
}
Trace.Assert(CountNodes(driver) == 0, "Expected transaction was rolled back.");
// Correct query.
using(var session = driver.Session())
using(var tx = session.BeginTransaction())
{
CreatePerson(tx, "mirka");
CreatePerson(tx, "slavka");
tx.Commit();
}
Trace.Assert(CountNodes(driver) == 2, "Expected 2 created nodes.");
ClearDatabase(driver);
using(var session = driver.Session())
{
// Create a lot of nodes so that the next read takes a long time.
session.Run("UNWIND range(1, 100000) AS i CREATE ()").Consume();
try
{
Console.WriteLine("Running a long read...");
session.Run("MATCH (a), (b), (c), (d), (e), (f) RETURN COUNT(*) AS cnt").Consume();
}
catch (TransientException)
{
Console.WriteLine("Transaction timed out");
}
}
}
Console.WriteLine("All ok!");
}
private static void CreatePerson(ITransaction tx, string name)
{
var parameters = new Dictionary<string, Object>{{"name", name}};
var result = tx.Run("CREATE (person:Person {name: $name}) RETURN person", parameters);
Console.WriteLine("Created: " + ((INode) result.First()["person"])["name"]);
}
private static void ClearDatabase(IDriver driver)
{
using(var session = driver.Session())
session.Run("MATCH (n) DETACH DELETE n").Consume();
}
private static int CountNodes(IDriver driver)
{
using(var session = driver.Session())
{
var result = session.Run("MATCH (n) RETURN COUNT(*) AS cnt");
return Convert.ToInt32(result.First()["cnt"]);
}
}
}

View File

@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Neo4j.Driver.Simple" Version="4.1.1" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,22 @@
#!/bin/bash -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$DIR"
# check if dotnet-sdk-2.1 is installed
for i in dotnet; do
if ! which $i >/dev/null; then
echo "Please install $i!"
exit 1
fi
done
for i in *; do
if [ ! -d $i ]; then
continue
fi
pushd $i
dotnet publish -c release --self-contained --runtime linux-x64 --framework netcoreapp2.1 -o build/
./build/$i
popd
done;