Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to upsert using jOOQ-generated record classes?

I can perform an insertInto().onDuplicateKeyUpdate() if I want to write my insert manually using the DSL, but is there an equivalent on the generated Record class?

like image 566
stickfigure Avatar asked Nov 08 '22 18:11

stickfigure


1 Answers

As of jOOQ 3.7, this is not yet possible out of the box. There's a pending feature request for this: #2961.

Alternatively, you can write a utility that translates an UpdatableRecord into a corresponding INSERT .. ON DUPLICATE KEY UPDATE statement. All the meta information needed for this is available from the UpdatableRecord:

  • Record.getTable() to discover the target table
  • Record.fields() to discover all the fields in a record
  • Table.getPrimaryKey() primary key information, if you need that
  • Record.changed() flags to discover the modified values of a record
like image 173
Lukas Eder Avatar answered Nov 14 '22 21:11

Lukas Eder