Hi All ~

I'm currently in the process of switching from slick to jooq, things are 
going fairly well so far, but one of the patterns I'm still trying to come 
up with a good syntax for is updating specific fields in a table.

For instance:

Brute force approach:

readWrite
  .update(CATALOG_USER)
  .set(CATALOG_USER.FIRST_NAME, r.firstName.getOrElse(null))
  .set(CATALOG_USER.LAST_NAME, r.lastName.getOrElse(null))
  .set(CATALOG_USER.COMPANY, r.company.getOrElse(null))
  .set(CATALOG_USER.ADDRESS1, r.address1.getOrElse(null))
  .set(CATALOG_USER.ADDRESS2, r.address2.getOrElse(null))
  .set(CATALOG_USER.CITY, r.city.getOrElse(null))
  .set(CATALOG_USER.STATE, r.state.getOrElse(null))
  .set(CATALOG_USER.ZIP, r.zip.getOrElse(null))
  .set(CATALOG_USER.COUNTRY, r.country.getOrElse(null))
  .set(CATALOG_USER.PHONE, r.phone.getOrElse(null))
  .set(CATALOG_USER.FAX, r.fax.getOrElse(null))
  .where(CATALOG_USER.CATALOG_ID === catalogId and CATALOG_USER.CATALOG_USER_ID 
=== catalogUserId)
  .execute


If you assume the r.firstName/etc are all Option[String] values, is there a 
good way to conditionally add the set statement in this pattern only if its set?


Is there a pseudo builder pattern I can use?  Or what do you use to optionally 
add a field to the .set?


val builder = readWrite.update(CATALOG_USER)


row.firstName.map{ builder += set(CATALOG_USER.FIRST_NAME, _) }

row.lastName.map{ builder += set(CATALOG_USER.LAST_NAME, _) }

row.lastName.map{ builder += set(CATALOG_USER.COMPANY, _) }

...


  builder.build().where(CATALOG_USER.CATALOG_ID === catalogId and 
CATALOG_USER.CATALOG_USER_ID === catalogUserId)
  .execute == 1


Thanks,


Eric

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to