In developing an application using Doma in the Spring Boot app, I am trying to control the generation of group by clauses by conditional comments in the SQL template, but there are some parts I don't understand, so please let me ask you a question.
If the where clause does not generate all the conditional expressions when dynamically assembling the conditional expressions with Dao method parameters in the SQL template of Doma, the where clause itself is not generated, but the group by clause seems to be left behind.
Template Description
group by
/*% if condition*/
col1,col2
/*%end*/
SQL generated when condition is false
group by
As far as the description in the document is concerned, conditional comments can be written in the group by clause.
http://doma.readthedocs.io/ja/stable/sql/ #id16
The if and end conditional comments must be in the same section of SQL. Sections include SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY, and so on.
For the time being, I am avoiding it by switching to a dummy group by item (equivalent to id) as follows, but unlike where clauses, commas are not edited.
group by
/*% if condition*/
col1,col2
/*%else*/
dummy -- grammatically I want to say ",dummy" but it generates "group by,dummy" and I get an error when running the app
/*%end*/
Please let me know if there is a way to solve the above problem.
Environment
Spring Boot: 1.5.2
domain-spring-boot-starter: 1.1.1
Doma: 2.16.1
You can avoid the issue of "If you interpret the whole thing as it is, it will not be the correct SQL" by hiding the problematic part with embedded comments.
group by
/*% if condition*/
col1,col2
/*%else*/
/*# "dummy" */
/*%end*/
© 2024 OneMinuteCode. All rights reserved.