I need to run the following query in QueryDsl Native MySQL.
SELECT cast(json_unquote(JSON_EXTRACT(vendor_master,'$.vendor.currency')) as char) as currency FROM vendor;
The above query has 3 mysql functions which are nested such as cast,json_unquote and json_extract.
In QueryDsl, I have created separate Expression for each function as shown in the below code.
SimpleExpression exp1=Expressions.simpleTemplate(String.class,"json_extract({0},{1})",vendor.vendorMaster,"$.vendor.currency");
SimpleExpression exp2=Expressions.simpleTemplate(String.class,"json_unquote({0})",exp2);
SimpleExpression exp3=Expressions.simpleTemplate(String.class,"cast({0} as char) as currency",exp3);
List tuples=sqlQueryFactory.select(exp3).from(vendor).fetch();
I have to create more number of expressions as much as no of functions. Is it possible to call more than one function in single expression in order to reduce complexity?
解决方案
I found the answer for the question.
SimpleExpression exp=Expressions.simpleTemplate(String.class,"cast(json_unquote(json_extract({0},{1})) as char) as currency",vendor.vendorMaster,"$.vendor.currency");
List tuples=sqlQueryFactory.select(exp).from(vendor).fetch();
Thanks for your response.