Graphr.Neo4j
0.1.1
See the version list below for details.
dotnet add package Graphr.Neo4j --version 0.1.1
NuGet\Install-Package Graphr.Neo4j -Version 0.1.1
<PackageReference Include="Graphr.Neo4j" Version="0.1.1" />
paket add Graphr.Neo4j --version 0.1.1
#r "nuget: Graphr.Neo4j, 0.1.1"
// Install Graphr.Neo4j as a Cake Addin #addin nuget:?package=Graphr.Neo4j&version=0.1.1 // Install Graphr.Neo4j as a Cake Tool #tool nuget:?package=Graphr.Neo4j&version=0.1.1
Graphr.Neo4j
Graphr.Neo4j is a lightweight ORM for Neo4j that focuses on easy set up and result mapping.
Cypher queries are incredibly flexible, and this project makes no attempt to write queries for you, as that would be a huge undertaking and probably just rob you of understanding what the heck you're doing.
Installation
Simply install via nuget in your favorite IDE (it's Rider), or use the command line.
Install-Package Graphr.Neo4j -Version 0.1.1
Usage
Dependency Injection Setup (if you're into that)
Add a section to your appsettings, environment variables, or whatever else (I'm not your dad) so you end up with something like this:
{
"NeoDriverConfigurationSettings": {
"url": "YOUR_URL_PROBALBY_BOLT:SOMETHING",
"username": "YOUR_USERNAME",
"password": "YOUR_PASSWORD",
"isDebugLoggingEnabled": true,
"isTraceLoggingEnabled": true
}
}
If you don't know where this goes, you shouldn't be trying to use this yet...
services.AddNeoGraphr(configuration);
Setting Up Your Entities
Now add some attributes to your beautiful entities!
[NeoNode("Person")]
public class Actor
{
[NeoLabels]
public IEnumerable<string> Labels { get; set; }
[NeoProperty("name")]
public string Name { get; set; }
[NeoProperty("born")]
public long Born { get; set; }
[NeoRelationship(type: "ACTED_IN", direction: RelationshipDirection.Outgoing)]
public IEnumerable<Movie> Movie { get; set; }
}
[NeoNode("Movie")]
public class Movie
{
[NeoProperty("tagline")]
public string Description { get; set; }
[NeoProperty("title")]
public string Title { get; set; }
[NeoProperty("released")]
public long Released { get; set; }
}
You can also inherit from [RelationshipEntity]
as long as you declare one of your props as
the [TargetNode]
like so:
[NeoNode("Person")]
public class Actor
{
[NeoProperty("name")]
public string Name { get; set; }
[NeoProperty("born")]
public long Born { get; set; }
[NeoRelationship(type: "ACTED_IN", direction: RelationshipDirection.Outgoing)]
public IEnumerable<ActorToMovieRelationship> Movie { get; set; }
}
[NeoRelationshipEntity]
public class ActorToMovieRelationship
{
[NeoProperty("roles")]
public IEnumerable<string> Roles { get; set; }
[NeoTargetNode]
public Movie Movie { get; set; }
}
[NeoNode("Movie")]
public class Movie
{
[NeoProperty("tagline")]
public string Description { get; set; }
[NeoProperty("title")]
public string Title { get; set; }
[NeoProperty("released")]
public long Released { get; set; }
}
If you're familiar with Neo4j, then these attributes are pretty self explanatory. If not, I encourage you to check out Neo4j's documentation or their Graph Academy and get learnt and then get back here.
Using Graphr to Query
Now that you've done all the setup, it's time to have some fun! Check out how easy it is!
// It's late, and I'm not testing this example in any way.
public class Neo4jRocks
{
private readonly INeoGraphr _neoGraphr;
public Neo4jRocks(INeoGraphr neoGraphr)
{
_neoGraphr = neoGraphr;
}
public async Task ReadSomeStuff()
{
// You'll need to return the nodes and relationships between them for those
// fancy attributes to work.
var query = "MATCH (a:Person {name:'Tom Hanks'})-[r:ACTED_IN]->(m:Movie) RETURN a, collect(r), collect(m)";
var actorsWithSingleMovie = await _neoGraphr.ReadAsAsync<Actor>(query);
... Do Stuff ...
}
}
Notes on Usage
You must return relationships between nodes in your queries if your models have relationship attributes
Relationship attributes can be placed on classes that are decorated with the
[NeoNode]
attribute or anIEnumerable
of a decorated classSince you're mapping to a class, return the single node that represents that starting point first in your query
This library maps relationships for a node only once per DFS chain to avoid circular references. The node will still be mapped with it's properties each time, but relationships mapped only once.
Road Map
Here's where my heads at and where I want to take this
- Split up child nugets so you don't get DI stuff in the base package
- Add
[NeoResult]
attribute to map non-node record responses -
Session configuration & database name support -
Healthchecks -
Driver Best Practices -
Support for Labels -
Better support for IEnumerables -
Simple node mapping (one to one and one to many) -
Circular Reference Issues -
Basic Dependency Injection Extension -
Mapping of[NeoRelationshipEntity]
attribute -
Mapping of Cypher Type List (simple) -
Cypher Temporal to CLR Conversions -
More configuration options
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net5.0
- Microsoft.Extensions.Configuration (>= 5.0.0)
- Microsoft.Extensions.DependencyInjection (>= 5.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 5.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 5.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 5.0.0)
- Neo4j.Driver (>= 4.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
8.0.1 | 2,244 | 7/9/2024 |
8.0.0 | 1,572 | 3/8/2024 |
0.1.6 | 8,161 | 3/13/2023 |
0.1.5 | 403 | 2/7/2023 |
0.1.3 | 2,129 | 9/12/2022 |
0.1.2 | 1,258 | 7/20/2022 |
0.1.1 | 489 | 7/19/2022 |
0.1.0 | 460 | 6/13/2022 |
0.0.14 | 937 | 5/18/2022 |
0.0.13 | 437 | 5/18/2022 |
0.0.12 | 441 | 5/18/2022 |
0.0.11 | 456 | 5/18/2022 |
0.0.10 | 787 | 3/18/2022 |
0.0.9 | 1,634 | 11/20/2021 |
0.0.8 | 409 | 10/10/2021 |
0.0.7 | 477 | 9/14/2021 |
0.0.6 | 334 | 8/25/2021 |
0.0.5 | 364 | 8/21/2021 |
0.0.4 | 379 | 8/20/2021 |
0.0.3 | 445 | 7/30/2021 |
0.0.2 | 403 | 7/29/2021 |
0.0.1 | 403 | 7/29/2021 |