Open up findAllByQuery in Repositories [DATACOUCH-651]
Eduard Dudar opened DATACOUCH-651 and commented
Repositories provide a very convenient way to work with CRUD operations but when it comes to search, they are rather restrictive and I usually resort to raw xxxTempalte or xxxOperations approach. A typical scenario would be users searching in a number of fields like email, zip code, last name, etc. Not all values will be available in every single query. Some will have zip codes, others last or first names, etc. Existing approaches with function name heuristics or @Query("... WHERE ...") are not flexible as both require to know all parameters beforehand. I've managed to do @Query("...") but the resulting N1QL expression is far from concise and readable as I have to assess optional params right in the query. Having accessible findAll(Query) would allow such dynamic queries to be created much easier. After all, every other findAll(...) calls it right away so exposing the function in (Reactive)CouchbaseRepository should not break anything
No further details from DATACOUCH-651
Michael Reiche commented
Eduard Dudar - I'm not sure why the findByAll(query) methods of spring-data repositories are not public. You can add it to your repository class :
import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.data.couchbase.core.CouchbaseTemplate;
ApplicationContext ac = new AnnotationConfigApplicationContext(Config.class); CouchbaseTemplate couchbaseTemplate = (CouchbaseTemplate) ac.getBean(COUCHBASE_TEMPLATE);
default List<Airport> findAll(final org.springframework.data.couchbase.core.query.Query query)
{ return couchbaseTemplate.findByQuery(Airport.class).matching(query).all(); }
Eduard Dudar commented
It does not seem like they have to be public in the spring-data ecosystem as a whole. Query belongs to spring-data-couchbase only and CouchbaseRepository adds custom findAll(QueryScanConsistency) already so findAll(Query) or even findAll(record(query, sort, consistency)) functions do not fall too out of line I think