Skip to content

weknow-network/Weknow.Cypher.Builder

Repository files navigation

Weknow Cypher Builder Beta.

Build & Deploy NuGet

Usage

Goals

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

Samples

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 become me1.Member.Name because of the SCREAMING_CASE convention

GraphDb Client

Make your first insert

  1. Define a schema
public ILabel Person => throw new NotImplementedException();
public IType Follow => throw new NotImplementedException();

Yes, we believe in schema 😃

  1. 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 of record Person.

  1. Write a Cypher query.
var map = Parameters.Create<PersonEntity>();

CypherCommand cypher = _(user =>
                        Create(N(user, Person, map)));

Produce: CREATE (user:Person $map)

  1. 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

About

This library is still in alpha phase. this means that the API still constantly changing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published