I'm trying to inject anything other than values using the @Query
N1QL query syntax but can't get it to work.
Here is the pure N1QL query:
SELECT * from `my-bucket` WHERE _class = 'my.package.MyModel' AND myParam = 'myValue'
I successfully manage to inject a value in Java and get the correct results:
// In my repository
@Query("#{#n1ql.selectEntity} WHERE myParam = $1 AND #{#n1ql.filter}")
Collection<MyModel> myCustomSearch(String value);
// In my business code
myRepository.myCustomSearch("myValue");
However I can't manage to inject anything else (like a param). This doesn't work:
// In my repository
@Query("#{#n1ql.selectEntity} WHERE $1 = 'myValue' AND #{#n1ql.filter}")
Collection<MyModel> myCustomSearch(String param);
// In my business code
myRepository.myCustomSearch("myParam");
Considering that in a pure N1QL query, the value usually is wrapped in single quotes ('') and it's not necessary when injecting it, I'm afraid spring-data-couchbase always wraps injected elements with single or double quotes (thus my query is transformed into
SELECT * from `my-bucket` WHERE _class = 'my.package.MyModel' AND 'myParam' = 'myValue'
which explains why Couchbase doesn't return any result).
Did I miss something? Otherwise, is there a way to bypass the quote injection from spring-data-couchbase?
I am aware I could simply use a com.couchbase.client.java.Bucket
and call query
on it, but this loses the whole point of spring-data-couchbase for me, which is to always manipulate POJOs and hide the JSON manipulation.
I appreciate any help!