Git Product home page Git Product logo

cyphernet's Introduction

CypherNet

Build status

A .Net API for the Neo4j HTTP Transactional Endpoint. (v2.0.0)

Exposes strongly typed Graph Query API based on the Neo4j Cypher Query Language.

Connection String

var clientFactory = Fluently.Configure("Server=http://localhost:7474/db/data/;User Id=neo4j;Password=password").CreateSessionFactory();
var cypherEndpoint = clientFactory.Create();

or for Unauthd:

var clientFactory = Fluently.Configure("http://localhost:7474/db/data/").CreateSessionFactory();
var cypherEndpoint = clientFactory.Create();

Usage

var clientFactory = Fluently.Configure("http://localhost:7474/db/data/").CreateSessionFactory();
var cypherEndpoint = clientFactory.Create();

var nodes = cypherEndpoint
    .BeginQuery(p => new {person = p.Node, rel = p.Rel, role = p.Node}) // Define query variables
    .Start(ctx => ctx.StartAtAny(ctx.Vars.person)) // Cypher START clause
    .Match(ctx => ctx.Node(ctx.Vars.person).Outgoing(ctx.Vars.rel).To(ctx.Vars.role)) // Cypher MATCH clause
    .Where(ctx =>
           ctx.Prop<string>(ctx.Vars.person, "name!") == "mark" && ctx.Prop<string>(ctx.Vars.role, "title!") == "developer")
    // Cypher WHERE predicate
    .Return(ctx => new { Person = ctx.Vars.person, Rel = ctx.Vars.rel, Role = ctx.Vars.role }) // Cypher RETURN clause
    .Fetch(); // GO!

/* Executes Cypher: 
 * START person:node(*) 
 * MATCH (person)-[rel]->(role) 
 * WHERE person.name! = 'mark' AND role.title! = 'developer' 
 * RETURN person as Person, rel as Rel, role as ROle
*/

Assert.IsTrue(nodes.Any());

foreach (var node in nodes)
{
    dynamic start = node.Person; // Nodes & Relationships are dynamic types
    dynamic end = node.Role;
    Assert.AreEqual("mark", start.name);
    Assert.AreEqual("developer", end.title);
    Console.WriteLine(String.Format("{0} {1} {2}", start.name, node.Rel.Type, end.title));
        // Prints "mark IS_A developer"
}

Transactional

var clientFactory = Fluently.Configure("http://localhost:7474/db/data/").CreateSessionFactory();
var cypherEndpoint = clientFactory.Create();
Node node1, node2;
using (var trans1 = new TransactionScope(TransactionScopeOption.RequiresNew, TimeSpan.FromDays(1)))
{
    node1 = cypherEndpoint.CreateNode(new {name = "test node1"});
    using (var trans2 = new TransactionScope(TransactionScopeOption.RequiresNew))
    {
        node2 = cypherEndpoint.CreateNode(new {name = "test node2"});
        trans2.Complete();
    }
}

var node1Query = cypherEndpoint.BeginQuery(s => new {node1 = s.Node})
                               .Start(ctx => ctx.StartAtId(ctx.Vars.node1, node1.Id))
                               .Return(ctx => new {ctx.Vars.node1})
                               .Fetch()
                               .FirstOrDefault();

var node2Query = cypherEndpoint.BeginQuery(s => new {node2 = s.Node})
                               .Start(ctx => ctx.StartAtId(ctx.Vars.node2, node2.Id))
                               .Return(ctx => new { ctx.Vars.node2 })
                               .Fetch()
                               .FirstOrDefault();

Assert.IsNull(node1Query);
Assert.IsNotNull(node2Query);

Me: http://www.mtranter.com

cyphernet's People

Contributors

andrew-dddd avatar chandu avatar gitter-badger avatar mtranter avatar

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.