neo4j / sdn-rx

Nextgen Spring Data module for Neo4j supporting (not only) reactive data access and immutable support
https://neo4j.github.io/sdn-rx
Apache License 2.0
65 stars 23 forks source link

Provide a way of defining custom queries in a static, type safe way. #181

Closed michael-simons closed 4 years ago

michael-simons commented 4 years ago

The idea is to use the Cypher-DSL inside the @Query annotation. The simplest option would be providing suppliers of statements:

    @API(status = EXPERIMENTAL, since = "1.0")
    Class<? extends StatementSupplier> statementSupplier() default DefaultQuerySupplier.class;

    @API(status = EXPERIMENTAL, since = "1.0")
    interface StatementSupplier extends Supplier<Statement> {
    }

    class PersonByNameStatementSupplier implements Query.StatementSupplier {

        @Override
        public Statement get() {
            return Cypher.match(
                node("PersonWithAllConstructor").named("n").properties(mapOf("name", Cypher.parameter("name"))))
                .returning("n").build();
        }
    }

    @Query(statementSupplier = PersonByNameStatementSupplier.class)
    Optional<PersonWithAllConstructor> getOptionalPersonViaStatementSupplier(@Param("name") String name);

With classes all over the place (one for each statement). We discussed possible lookups with method handles.

Also nice to have would be something along the test introduced in #180 so that standalone building blocks - mostly reassembly Cypher with blocks can be reused and stacked together.

This is a place holder for a pre 1.0 release.

meistermeier commented 4 years ago

Since we are in a migration process to the original Spring Data Neo4j and have to archive this repository, the issue also go migrated to: https://jira.spring.io/browse/DATAGRAPH-1349 Please watch or comment on the issue in Jira for further communication.