kotlin-jdsl
kotlin-jdsl copied to clipboard
Add support for paramters in `function` function
In QueryDSL we can use parameters like {0}
, {1}
to parse parameters.
But JDSL only supports varargs style functions.
Example (QueryDSL)
Simple example using QueryDSL
Expressions.dateTemplate(Date::class.java, "CAST({0} AS date)", QEntity.entity.createdAt).eq(date)
JSDL
I expected this would work like QueryDSL but it didn't.
function("CAST({0} AS date)", Date::class.java, col(Entity::createdAt)).equal(date)
Hi, asomethings.
I checked how QueryDSL provides the above form of code. It converts the template to JPQL String and creates javax.persistence.Query through JPQL String.
When I checked the Criteria API, it seems that there is no way to put string directly in the javax.persistence.criteria.Expression.
It would have been possible if Kotlin-JDSL had been written based on JPQL, but it is impossible because it is based on the Criteria API.
Kotlin-JDSL, like QueryDSL, will consider how to create queries based on JPQL strings. However, even if internal decisions are made by making Kotlin-JDSL based on JPQL strings, the work will take a lot of time.
Unfortunately, if you have to use a query such as the above, you have to use JPQL directly or QueryDSL now. I'm sorry for the bad news.
Hi @asomethings
Kotlin JDSL 3.0.0-SNAPSHOT has been released in snapshot repository. With 3.0.0, custom expression is now possible. If you are still using Kotlin JDSL, please test it.
We apologize for the long wait and thank you for your patience.
If the snapshot version doesn't allow you to write the code you need, please reopen this issue.
I think the following docs will help you get started with Kotlin JDSL 3.0.0. https://kotlin-jdsl.gitbook.io/docs/