- Weknow.Cypher.Builder: Produce Cypher Query from structural C# builder.
dotnet add package Weknow.Cypher.Builder
- Weknow.GraphDbClient.Abstraction: Abstract Graph Database client.
dotnet add package Weknow.GraphDbClient.Abstraction
- Weknow.GraphDbClient.Redis: Client implementation for Redis Graph (Not implementes yet).
dotnet add package Weknow.GraphDbClient.Redis
- Weknow.GraphDbClient.Neo4j: Client implementation for Neo4j.
dotnet add package Weknow.GraphDbClient.Neo4j
Cypher Builder aim to be developer friendly library for cypher query. It bring as match intellisense & cypher correction as it can while keeping the Cypher expression readable and well documented.
When this library evolve over time, we consider:
- Source code generation which will provide a type-safe parameters
- Analyzer which will recommend best practice
var n = Variables.Create();
var Id = Parameters.Create();
CypherCommand cypher = _(() => Match(N(n, Person & Manager, new { Id }))
.Return(n));
Produce:
MATCH (n:Person:Manager {{ Id: $Id }}) RETURN n
var items = Parameters.Create();
var n = Variables.Create();
var map = Variables.Create<Foo>();
CypherCommand cypher = _(() =>
Unwind(items, map,
Merge(N(n, Person, new { map.__.Id, map.__.Name }))
.OnCreateSet(n, map)
.Return(n)),
cfg => cfg.Naming.Convention = CypherNamingConvention.SCREAMING_CASE);
Produce:
UNWIND $items AS map
MERGE (n:me1.Member.Name {{ Id: map.Id, Name: map.Name }})
ON CREATE SET n = map
RETURN n
Note: The label
Person
becomeme1.Member.Name
because of theSCREAMING_CASE
convention
- Define a schema
public ILabel Person => throw new NotImplementedException();
public IType Follow => throw new NotImplementedException();
Yes, we believe in schema 😃
- Create entity class/record.
[Dictionaryable(Flavor = Flavor.Neo4j)]
private partial record Person(string name, int age);
Node:
[Dictionaryable]
is using Weknow.Mapping.Generation.SrcGen in order to generate serialization code out ofrecord Person
.
- Write a Cypher query.
var map = Parameters.Create<PersonEntity>();
CypherCommand cypher = _(user =>
Create(N(user, Person, map)));
Produce:
CREATE (user:Person $map)
- To execute the query, you can use GraphDb Client.
CypherParameters prms = cypher.Parameters
.AddOrUpdate(nameof(map), new Person("Nina", 76));
await _graphDB.RunAsync(cypher, prms);
See more on our wiki