I have a case coming up more and more... a `@Komap...
# komapper
d
I have a case coming up more and more... a
@KomapperPartial
that has two parts... the WITH ... before the sql I need to put it in and the actual place I need it in (like adding a JOIN to that WITH, or an ORDER BY by it...). One possibility is having the annotation be able to receive an array of sql parts (using the same parameters in the class they're annotating), and then being able to use it:
Copy code
@KomapperPartial([
"""....""",
"""...."""
]) data class P(...)

@KomapperCommand("""
   /*> p.1 */
....
   /*> p.2 */
...
""") data class Q(p: P, ...)...
this would help encapsulate a whole functionality in one partial.
t
Thank you for sharing your idea. Personally, I don’t find arrays very intuitive. If the goal is to have a common data structure shared across multiple partials, how about writing it like this?
Copy code
@KomapperPartial("with x (/*# common.a */, /*# common.b */)")
data class P1(common: Common)

@KomapperPartial("order by /*# common.a */, /*# common.b */")
data class P2(common: Common)

@KomapperCommand("""
   /*> p1 */
....
   /*> p2 */
...
""") 
data class Q(p1: P1, p2: P2)
d
This is not quite as nice when I have a sealed interface hierarchy of such PXs... like Popularity.Likes, Popularity.Followers, then I'd need to create 2 of them for each option, and have my command have two per config option... I agree that arrays aren't too nice... I guess for now I'll just try to work around this problem...
@Toshihiro Nakamura I have maybe a much better idea:
Copy code
@KomapperPartial("") // What could I write here...
data class P(p1: P1, p2: P2)
That way they're grouped together, and there's no arrays... I can pass them together to the command using them.
It still gets a bit messy in a big hierarchy... but I guess I can maybe work that part out.
It seems to already work like that 👍🏼.
t
You can do that even with the current version.
Copy code
@KomapperPartial(
    """
    limit /* value */0
    """,
)
data class Limit(val value: Int)

@KomapperPartial(
    """
    offset /* value */0
    """,
)
data class Offset(val value: Int)



data class Pagination(limit: Limit, offset: Offset)


@KomapperCommand(
    """
    select * from address order by address_id
    /*> pagination?.limit */
    /*> pagination?.offset */
    """,
)
class UsePartial(val pagination: Pagination?) : Many<Address>({ selectAsAddress() })
d
Yeah, but it just won't work w/o using an empty string partial annotation on Pagination...
t
That’s not the case. It works in my environment.