on ‎2023 Oct 11 6:41 AM
Hello community,
we are using CAP Java and want to use the $count query in a custom handler:
Query:
http://localhost:8080/api/play/Books/$count

We are using the CqnAnalyzer to check if this is a $count query or not. Normally we return a list of Books but we don't know, how we can return the response for a $count query.
If we return the List of Books as well we are getting the error:

So what is the correct way to return the result for $count?
In the documentation I just found how to pass the inlinecount by using the ResultBuilder.
Result r = selectedRows(asList(row)).inlineCount(inlineCount).result();
Best regards and many thanks,
Chris
Request clarification before answering.
The $count query from OData is done by sending a CqnSelect containing only a count(*) function with alias count. Therefore the expected result structure would be something like this:
Arrays.asList(Collections.singletonMap("count", value));You can adapt your method signature to use return type List<Map<String, Object>>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I opened a PR to improve this in our docs: https://github.com/cap-js/docs/pull/495
| User | Count |
|---|---|
| 9 | |
| 7 | |
| 6 | |
| 4 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.