jklingsporn / vertx-jooq

A jOOQ-CodeGenerator to create vertx-ified DAOs and POJOs.
MIT License
384 stars 53 forks source link

Using QueryExecutor for Nested data structures #214

Open ivanovdns opened 2 years ago

ivanovdns commented 2 years ago

Hello! I need some assistance in fetching nested data structures by jooq. JOOQ provides dsl:

record Name(String firstName, String lastName) {}
record Book(int id, String title) {}
record Author(int id, Name name, List<Book> books) {} // Is now using a List<Book> instead of Book[]

// Again, no structural typing here has gone!
List<Author> authors =
create.select(
         AUTHOR.ID,
         row(AUTHOR.FIRST_NAME, AUTHOR.LAST_NAME).mapping(Name::new),
         array(
           select(row(BOOK.ID, BOOK.TITLE).mapping(Book.class, Book::new)
           .from(BOOK)
           .where(BOOK.AUTHOR_ID.eq(AUTHOR.ID))
         ).convertFrom(Arrays::asList) // Additional converter here
       )
      .from(AUTHOR)
      .fetch(Records.mapping(Author::new));

Is it possible to use this API in conjunction with vertx and vertx-jooq libraries?

jklingsporn commented 1 year ago

Sorry for the late response. That should work when using a jdbc-module with an instance of io.github.jklingsporn.vertx.jooq.shared.internal.jdbc.JDBCQueryExecutor. When you want to go reactive, I'm afraid we're limited to the mapping capabilities of the reactive pg client.