简体   繁体   中英

How to get a Row representation of a generated table?

I want to get Row[N]<...> representation of a generated JOOQ table type. I want to use it in this context:

val p = PROJECTS.`as`("p")
val pmu = PROJECTMEMBERUSERS.`as`("pmu")
val query = db
    .select(p.asterisk(), DSL.arrayAgg(DSL.rowField(<-- insert Row[N]<...> here -->)))
    .from(p.join(pmu).on(p.ID.eq(pmu.PROJECTID)))
    .groupBy(p.ID)

I already tried inserting pmu.fieldsRow() , but DSL.rowField(...) expects another parameter type.

Error:(39, 58) Kotlin: None of the following functions can be called with the arguments supplied [...]

This question is a follow up question to Using PosgreSQL array_agg with join alias in JOOQ DSL but should be self contained.

Missing feature in jOOQ 3.11

There seems to be a missing feature in the jOOQ code generator, a generated Table.fieldsRow() overridden method that provides a more narrow, covariant Row[N]<...> return type. I've created a feature request for this, to be implemented in jOOQ 3.12: https://github.com/jOOQ/jOOQ/issues/7809

Also missing, an overloaded DSL.rowField(RowN) method: https://github.com/jOOQ/jOOQ/issues/7810

Workaround, list columns explicitly

This is the most obvious workaround, which you obviously want to avoid: Listing all the column names explicitly:

row(pmu.COL1, pmu.COL2, ..., pmu.COLN)

Workaround, use generated records

There already is such a generated method in generated records. As a workaround, you could use

new ProjectMembersUsersRecord().fieldsRow();

Workaround, extend the code generator

You can implement #7809 yourself already now, by extending the JavaGenerator with a custom code section:

https://www.jooq.org/doc/latest/manual/code-generation/codegen-custom-code

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM