Giter VIP home page Giter VIP 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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cyphernet's Issues

Creating a full path is possible?

From Neo4J docs:

Create a full path
When you use CREATE and a pattern, all parts of the pattern that are not already in scope at this time will be created.

Query

CREATE p =(andres { name:'Andres' })-[:WORKS_AT]->(neo)<-[:WORKS_AT]-(michael { name:'Michael' })
RETURN p

This query creates three nodes and two relationships in one go, assigns it to a path identifier, and returns it.

http://neo4j.com/docs/milestone/query-create.html#create-create-a-full-path

It's possible with CypherNet this query?

.where clause with logic operation

help me with .where clause, please. i try something like "match a,b where NOT a-->b return b", but couldn't found how i can do this in cyphernet

Cannot find server Version

image

Hi, I tried to connect to my local neo4j database and got the error "Cannot find server Version". What does that mean in the context of this library? I have no trouble with Neo4jClient library, so I didn't anticipate anything with this.

I appreciate any insight. Thank you.

M

GraphEntity Tracking

Should we provide entity tracking? Probably not difficult.. Entity Cache in the Session object and some INotifyPropertyChanged type hoo haa in GraphEntity???

Trouble querying nodes of specific label (type)

Probably my noobness but this query should return only nodes labeled "Movie" right? It actually return all nodes in the database.

var nodes = cypherEndpoint
    .BeginQuery(p => new {Movie = p.Node})
    .Match(ctx => ctx.Node(ctx.Vars.Movie))
    .Return(ctx => new {Movie = ctx.Vars.Movie})
    .Fetch();

The code generates:
MATCH (Movie) RETURN Movie as Movie, id(Movie) as Movie__Id, labels(Movie) as Movie__Labels

But should generate:
MATCH (Movie:Movie) RETURN Movie as Movie, id(Movie) as Movie__Id, labels(Movie) as Movie__Labels

Am I missing something here in my code? :)

Expose the Cypher Query as text

A feature to get hold of the last query that the querybilder (CypherEndPoint) have created. For simpler debuging.

(Nice library BTW. :))

CypherNet json serialization

Hi.
I think i've found something wrong in cyphernet. here is the scenario:

I have a person class like this:

public class Person
{
private int age;
private string famil;
private string name;

    public String Name
    {
        get { return name; }
        set { name = value; }
    }

    public String Famil
    {
        get { return famil; }
        set { famil = value; }
    }

    public int Age
    {
        get { return age; }
        set { age = value; }
    }
}

If i want to create a node like the code below, every thing is OK.

neo4JClient = Fluently.Configure("http://localhost:7474/db/data/").CreateSessionFactory().Create();
person = new Person()
{
Name = "hooman",
Famil = "rouhani",
Age = 31,

        };

neo4JClient.CreateNode(person, "Person");

But

If i only don't set Age property like the code below i will give an error.

neo4JClient = Fluently.Configure("http://localhost:7474/db/data/").CreateSessionFactory().Create();
person = new Person()
{
Name = "hooman",
Famil = "rouhani"
};

neo4JClient.CreateNode(person, "Person");

Error detail is:

Debug Trace:
Info: Executing: {"statements":[{"statement":"CREATE (NewNode:Person {"Name":"hooman","Famil":"rouhani","Age":0}) RETURN NewNode as NewNode, id(NewNode) as NewNode__Id, labels(NewNode) as NewNode__Labels;","parameters":{}}]}
Info: Response: {"results":[],"errors":[{"code":"Neo.ClientError.Statement.InvalidSyntax","message":"Invalid input '"': expected whitespace, an identifier, '}' or UnsignedInteger (line 1, column 25)\n"CREATE (NewNode:Person {"Name":"hooman","Famil":"rouhani","Age":0}) RETURN NewNode as NewNode, id(NewNode) as NewNode__Id, labels(NewNode) as NewNode__Labels;"\n ^"}]}

Test method Neo4jCypherNetPractice.Neo4jCypherNetTest.TestDelete threw exception:
Newtonsoft.Json.JsonReaderException: Error reading string. Unexpected token: StartObject. Path 'errors[0]', line 1, position 25.
at Newtonsoft.Json.JsonReader.ReadAsStringInternal()
at Newtonsoft.Json.JsonTextReader.ReadAsString()
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType(JsonReader reader, JsonContract contract, Boolean hasConverter)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader)
at CypherNet.Serialization.DefaultJsonSerializer.Deserialize(String json)
at CypherNet.Transaction.NonTransactionalCypherClient.ExecuteQuery(String cypherQuery)
at CypherNet.Transaction.CypherSession.CreateNode(Object properties, String label)
at Neo4jCypherNetPractice.Neo4jCypherNetTest.TestDelete()


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.