![]() |
VOOZH | about |
dotnet add package Grom --version 0.2.0-alpha
NuGet\Install-Package Grom -Version 0.2.0-alpha
<PackageReference Include="Grom" Version="0.2.0-alpha" />
<PackageVersion Include="Grom" Version="0.2.0-alpha" />Directory.Packages.props
<PackageReference Include="Grom" />Project file
paket add Grom --version 0.2.0-alpha
#r "nuget: Grom, 0.2.0-alpha"
#:package Grom@0.2.0-alpha
#addin nuget:?package=Grom&version=0.2.0-alpha&prereleaseInstall as a Cake Addin
#tool nuget:?package=Grom&version=0.2.0-alpha&prereleaseInstall as a Cake Tool
Grom, a .NET graph database object relational mapper.
Grom is an easy to use, low config ORM that lets you map your C# classes to nodes and relationships in various graph databases. This project is currently not production ready as it's still in beta. Version 1.0 is expected to release in Q4 2022.
Since this project is open source and currently only worked on by the maintainer a 'beta' phase was needed in which a pre-production version is released so bugs can be found and fixed and important missing features can be requested before an actual production ready version is released.
Feel free to try it out and if some feature is missing don't hesitate to open an issue!
Configuring Grom is easy, it only requires a database connection to be given to GromGraph.CreateConnection(...). You don't need to instantiate this class or call it anywhere after running CreateConnection once.
To configure Grom for Neo4J simply use:
GromGraph.CreateConnection(GraphDatabase.Driver("bolt://localhost:7687", AuthTokens.Basic("neo4j", "test")));
Any valid instance of Neo4J IDriver can be passed, so you are not restricted to username/password authentication.
To map a class as a node you have to do two things: inherit from EntityNode and annotate each property you want to map with NodeProperty. Grom does also require an empty constructor for all nodes.
A mapped class can be as simple as:
public class Person : EntityNode
{
[NodeProperty]
public string Name { get; set; }
[NodeProperty]
public int Age { get; set; }
}
Currently integer, boolean, string, float, long, DateTime and DateOnly are supported.
To persist a node simply call Persist() on any of your objects that inherit from EntityNode.
var personNode = new Person("John", 25);
await personNode.Persist();
Grom is fully asynchronous so make sure you await when required.
Updating a node is also done by calling Persist(). Grom will figure out if the node is allready created or not.
var personNode = new Person("John", 25);
await personNode.Persist();
personNode.Age = 30;
await personNode.Persist();
Do note that Grom only knows that a node exists if you have called Persist() on it or have retrieved it with Retrieve. It wont check if a node exists with the same properties in the database!
A node can be deleted by calling DeleteNode().
await personNode.DeleteNode();
The actual object in your code will still exist but the node and all its relationships to other nodes will be deleted in the database.
Nodes can be retrieved using Retrieve<T>. Nodes can be filtered by simply giving a lambda function that has a single parameter (the root node) and returns a boolean. Grom turns the lambda function into a query for you.
var personNode = await Retrieve<Person>
.Where(p => p.Name == "John")
.GetSingle();
Boolean operators such as &&, ||, !, ==, !=, >, <, >= and ⇐ are supported. Properties can be compared to constants, variables, method calls with no parameters and properties or fields in objects. Do note however that Grom can't turn everything a lambda can do into a query. Try to keep the lambda simple.
For now only directed relationships are supported. Release 1.0 will also include support for undirected relationships.
To define a relationship between nodes we first need to create a relationship entity. The entity needs to inherit from RelationshipBase and needs an empty constructor. Each property you want to map can be annotated with RelationshipProperty. A relationship entity will look something like this:
public class Knows : RelationshipBase
{
[RelationshipProperty]
public int ForYears { get; set; }
public Knows()
{
}
public Knows(int forYears)
{
ForYears = forYears;
}
}
To define a relationship between nodes simply add a new property with type RelationshipCollection. This collection needs two arguments: a relationship type and a target node type.
public class Person : EntityNode
{
[NodeProperty]
public string Name { get; set; }
[NodeProperty]
public int Age { get; set; }
public RelationshipCollection<Knows, Person> knownPeople { get; set; } = new();
public Person()
{
}
public Person(string name, int age)
{
Name = name;
Age = age;
}
}
A relationship is added by adding an item to this collection:
var person1 = new Person("John", 25);
var person2 = new Person("Doe", 26);
person1.knownPeople.Add(new Knows(5), person2);
await person1.Persist();
Calling Persist() will, in adition to the node, also persist or update any descendant nodes and relationships. Updating works the same way as with nodes, change the property and call Persist() again on any ancestor node.
To delete a relationship you can use the Remove, RemoveAt or RemoveRange methods on RelationshipCollection. They work the same as in a List<T>.
Currently only Neo4J is supported. With the release of version 1.0 Azure Cosmos DB will also be supported.
Comming soon.
Grom is open source so feel free to checkout (pun intended) the repo to see the code, features being worked on and maybe even to create a PR yourself! We also have an issue board to have a nice overview of the issues we have and the ones being worked on. Bugs can be reported on the discussions page here.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.2.0-alpha | 311 | 8/12/2022 |
| 0.1.1-alpha | 267 | 7/31/2022 |