GithubHelp home page GithubHelp logo

graphy-db's Introduction

GraphyDb

This repository contains a graph database GraphyDb written using .NET Framework (version 4.7).

All classes you need belong to namespace GraphyDb

How to create Nodes, Relations and assign Properties

Open database connection:

DbEngine engine = new DbEngine();

DbEngine implements interface IDisposable to nicely close all open file streams. After finishing your work with DB you should call method Dispose() by yourself or use operator using

using (var engine = new DbEngine()) {
    ...
}

Create new node with label "user" (every node must have a label):

Node user1 = engine.AddNode("user");

Add property "age" (propety keys must be strings) with value 19 to user1:

user1["age"] = 19;

GraphyDb currently supports node and relation properties with one of the following types of values:

  • int
  • float(32 bit)
  • bool
  • string (max length 16 unicode characters)

Add one more node with label "user" with property "age" set to 20:

Node user2 = engine.AddNode("user");
user2["age"] = 20;

Create relation with label "knows" from user1 to user2:

var relation1 = engine.AddRelation(user1, user2, "knows")

You can also assign properties to relations:

relation1["some_property"] = "zzz";

To commit changes (write them on disk):

engine.SaveChanges();

How to delete Nodes, Relations, properties

You can delete Nodes and Relations via uniform syntax:

engine.Delete(x); // x can be a Node or Relation

Or call method Delete directly on Node or Relation:

x.Delete(); // x can be a Node or Relation

To delete property:

x.DeleteProperty("property_name"); // x can be a Node or Relation

Do not forget to commit changes on disk:

engine.SaveChanges();

How to make queries

5 classes were created for querying:

  • NodeDescription(string label, Dictionary<string, object> props)
  • RelationDescription(string label, Dictionary<string, object> props)

NodeDescription and RelationDescription encapsulate required search parameters for Nodes and Relations respectively: you can search them by label (place null if you don't want to specify label) and by properties (place empty dictionary if you don't want to specify properties). Also there are shortcuts NodeDescription.Any() and RelationDescription.Any(), which match all Nodes / Relations.

  • NodeSet
  • RelationSet

These classes represent results of a Query. nodeSet.Nodes is a HashSet<Node> with found Nodes. relationSet.Relations is a HashSet<Relation> with found Relations

  • Query(DbEngine engine)

The main class to create a Query. The following examples will help you understand its syntax:

To get all Nodes matching particular nodeDescription:

var query = new Query(engine);

var nodeSet = query.Match(nodeDescription);

query.Execute();

After query.Execute(); nodeSet with be populated with found nodes.

More complex example:

var query = new Query(engine);

var A = query.Match(nodeDescriptionForA);
var x = query.From(relationDescriptionForX);
var B = query.Match(nodeDescriptionForB);
var y = query.To(relationDescriptionForY);
var C = query.Match(nodeDescriptionForC);

query.Execute();

After query.Execute(); objects A, B and C (which are of class NodeSet) will be populated with Nodes; x, y (which are of class RelationSet) will be populated with Relations such that:

A <-x- B -y-> C (x is a relation from B to A and y is a relation from B to C) considering all node and relation descriptions. With this simple syntax you can create as complex queries as you want.

To delete entire database

engine.DropDatabase();

graphy-db's People

Contributors

and-kul avatar valenzione avatar vkurenkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

graphy-db's Issues

Project Still Active?

Hello,

I have been searching for a simple C# Graph Database that I can use in a project and also learn from when I came across yours.

I am wondering if the project is still ative?

And also, I see the statement:

DbEngine engine = new DbEngine();

I am wondering where I define the database name to open and where the database files are stored?

Also, do you have some simple examples beyond what is given in the Remo as that example is a bit hard to follow.
Thanks and have a great day

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.