简体   繁体   中英

How can I project all database columns of a fast changing database?

I often have the situation that the generated jooq code doesn't match the database in production (columns get added all the time).

How can I fetch a weakly typed record, that contains all the database columns?

dsl.select(asterisk())
   .from(PERSON)
   .where(PERSON.PERSON_NO.eq(id))
   .fetch()

Only returns the columns known at code generation.

Just use plain SQL: https://www.jooq.org/doc/3.14/manual-single-page/#query-vs-resultquery

If that won't work for you, explaining why not might help someone formulate a more suitable answer.

A quick hack would be to make sure jOOQ doesn't know your tables by using plain SQL templating in your from clause. That way, jOOQ cannot resolve the asterisk and will try to discover the projection from the actual query results. For example:

dsl.select(asterisk())
   .from("{0}", PERSON)
   .where(PERSON.PERSON_NO.eq(id))
   .fetch();

This has been a re-occurring request, I guess we can turn this into a feature: https://github.com/jOOQ/jOOQ/issues/10182

Note though, that it is usually better to make sure jOOQ knows the exact production schema and keep generated code up to date. A future jOOQ will support versioned generated meta data so that the same code can work with different production schema versions more easily: https://github.com/jOOQ/jOOQ/issues/4232

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