dave08
09/11/2024, 4:04 PMAS foo
to the field in select that it should use that in the order by?Toshihiro Nakamura
09/11/2024, 11:45 PMval q1 =
QueryDsl.from(e).where { e.employeeId eq 1 }
.select(e.employeeId alias "ID", e.employeeName alias "NAME")
val q2 = QueryDsl.from(a).where { a.addressId eq 2 }
.select(a.addressId alias "ID", a.street alias "NAME")
val query = (q1 union q2).orderBy("ID", desc("NAME"))
dave08
09/12/2024, 1:42 AMdave08
09/12/2024, 1:44 AMdave08
09/12/2024, 9:13 AMdesc("NAME")
because there's no orderBy that takes in character sequences... is there any workaround for this @Toshihiro Nakamura?dave08
09/12/2024, 9:14 AMdave08
09/12/2024, 9:16 AMdave08
09/12/2024, 9:16 AMdave08
09/12/2024, 9:39 AMprivate inline fun alias(
alias: String
): ColumnExpression<String, String> {
val name = "alias"
return columnExpression({ it }, name, listOf()) {
append("\"$alias\"")
}
}
I use that in the orderBy... but it does surround the fields with (..), and it's not such a nice hack, but at least the sql is valid and the subqueries aren't repeated...dave08
09/12/2024, 2:04 PMToshihiro Nakamura
09/12/2024, 3:11 PMI guess it would be MUCH nicer if Partials could be on classes like I suggested in another thread... it would greatly simplify the parameters passed the main template...I will implement it in the next release.
the only catch in this use-case is that I’d need to find a way to provide one of a few types of templates in the same slot...I’m probably not understanding the issue you’re facing. Could you provide a sample code?
dave08
09/12/2024, 3:20 PMsealed interface Criteria
@KomapperPartial("""...""")
class CriteriaByDateInterval(val startDate..., val endDate) : Criteria
@KomapperPartial("""...""")
class CriteriaByPopularity(val ...) : Criteria
@KomapperCommand("""
...
/*> criteria */
""")
class GetFoo(val ..., val criteria: Criteria? = null)
@Toshihiro Nakamuradave08
09/12/2024, 3:22 PM@KomapperCommand("""
...
/*> criteriaByDate */ /*> criteriaByPopularity */
""")
class GetFoo(val ..., val criteriaByDate: CriteriaByDateInterval? = null, val criteriaByPopularity: CriteriaByPopularity? = null)
since anyways there can only be one of the two and not both...dave08
09/12/2024, 3:38 PMwhen
to test which instance of Criteria was passed down to resolve what needs to be interpolated in /*> criteria */
and since it's a sealed interface
so there's only a limited number of implementations that can be listed by ksp (?) on the sealed interface
... the only little thing, is that my use case has two levels of sealed interfaces and some are nested others not Criteria.Popularity.Likes vs Criteria.Likes (where Likes still inherits Popularity which inherits Criteria, but it's only nested in Criteria), which could complicate things...dave08
09/12/2024, 3:40 PMconst val
version... since that can't have multiple implementations passed down...Toshihiro Nakamura
09/14/2024, 2:35 AMdave08
09/15/2024, 9:49 AM