Skip to content

Support derived query methods from method names #12

@kornelrabczak

Description

@kornelrabczak

Problem

The library currently has limited or no support for Spring Data-style derived query methods. Users must write explicit Cypher queries using @Query annotations for even simple lookups, which reduces developer productivity and increases boilerplate.

Current Workaround

public interface PersonRepository extends NodeRepository<Person, String, Void, Person> {
    // Required: Explicit @Query for everything
    @Query("MATCH (n:Person) WHERE n.age > $age RETURN n")
    List<Person> findByAgeGreaterThan(@Param("age") int age);
    @Query("MATCH (n:Person {name: $name}) RETURN n")
    Optional<Person> findByName(@Param("name") String name);
    @Query("MATCH (n:Person) WHERE n.age >= $min AND n.age <= $max RETURN n")
    List<Person> findByAgeBetween(@Param("min") int min, @Param("max") int max);
    @Query("MATCH (n:Person) WHERE n.active = true RETURN n ORDER BY n.name")
    List<Person> findByActiveTrueOrderByByName();
}

Expected Behavior (Spring Data Style)

public interface PersonRepository extends NodeRepository<Person, String, Void, Person> {
    // Automatic query derivation
    List<Person> findByAgeGreaterThan(int age);
    Optional<Person> findByName(String name);
    List<Person> findByAgeBetween(int min, int max);
    List<Person> findByActiveTrueOrderByByName();
    List<Person> findByAgeIn(List<Integer> ages);
    List<Person> findByNameContaining(String substring);
    List<Person> findByNameIgnoreCase(String name);
    boolean existsByAge(Integer age);
    long countByActiveTrue();
    void deleteByAgeLessThan(int age);
}

Proposed Solution

Implement a query derivation mechanism that parses method names and generates Cypher queries automatically.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions