GithubHelp home page GithubHelp logo

bit-whacker / cypher-dsl Goto Github PK

View Code? Open in Web Editor NEW

This project forked from neo4j-contrib/cypher-dsl

0.0 2.0 0.0 650 KB

A Java DSL for the Cypher Query Language and an optional Query DSL mode

License: Other

Java 100.00%

cypher-dsl's Introduction

This module provides a Java DSL for the Cypher query language. Using the DSL you can either build up an expression that can be stringified, or you can access the internal query model.

There are two main modes: using static methods or Java instance initialization blocks.

Example usage with statics:

assertEquals( "START n=node(1) RETURN n",
              start( node( "n", 1 ) ).returns( nodes( "n" ) ).toString() );

Example usage with Java instance initialization block:

assertEquals( "START john=node(0) RETURN john", new CypherQuery()
{{
    starts( node( "john", 0 ) ).returns( nodes( "john" ) );
}}.toString() );

Once you have the constructed query string this can be sent to the Cypher execution engine. Example:

Execute q = start(node("john", john)).
            match(path().from("john").out("friend").link().out("friend").to("fof")).
            returns(properties("john.name", "fof.name"));
ExecutionResult result = engine.execute( q.toString() ).toString();

QueryDSL integration

It is possible to use the QueryDSL library and predicates with this DSL. Here's an example:

QPerson person = QPerson.person;
Assert.assertEquals( "START person=node(1,2,3) WHERE person.firstName=\"P\" and person.age>25 RETURN person",
                     CypherQueryDSL.start( node( "person", 1, 2, 3 ) )
                         .where( person.firstName.eq( "P" ).and( person.age.gt( 25 ) ) )
                         .returns( nodes( "person" ) )
                         .toString() );

Apart from using QueryDSL for the where-expression, it is also possible to create the Lucene index lookups using QueryDSL.

QPerson person = QPerson.person;
Assert.assertEquals( "START person=node:node_auto_index(\"firstName:rickard\") RETURN person",
                     CypherQueryDSL.start( LuceneStartExpression.query("person", "node_auto_index", person.firstName.eq("Rickard")) )
                         .returns( nodes( "person" ) )
                         .toString() );

See the POM and tests of this module for further examples and how to use these features.

cypher-dsl's People

Contributors

davided avatar jexp avatar nawroth avatar ractive avatar rickardoberg avatar simpsonjulian avatar systay avatar tbaum avatar timmystorms avatar treo avatar wgorder avatar wouterv avatar

Watchers

 avatar  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.