-
Notifications
You must be signed in to change notification settings - Fork 359
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fragments.setOpt removed #1893
Comments
Oh interesting I was not aware it ever existed 😮 We can add a |
That's a thing I've came across in the past, runtime errors because all the options were empty in the update case class and therefore it yielded a invalid query. With RC4 I've coded this val updateAttributes = {
val updates = List(
update.name.map(n => fr"name = $n"),
update.location.map(n => fr"location = $n"),
update.description.map(n => fr"description = $n"),
update.waterSchedule.map(n => fr"watering_schedule = $n")
)
NonEmptyList.fromList(updates.flatten) match {
case Some(update) =>
fr"UPDATE stations ${Fragments.set(update :+ fr"updated = $now")} WHERE id = $id AND user_id = $userId".update.run
case None =>
Applicative[ConnectionIO].pure(0)
}
}
Which does the job, but I'm sure it can be prettier with specific function for this case |
Perhaps something like So if columnUpdates is empty then it'll return None so the user knows to deal with when no columns are updated. |
Introduce `updateSetOpt` fragment (#1893)
This was quite useful for dynamic updates:
andOpt
does not work with updates as it's comma based in PostgresThe text was updated successfully, but these errors were encountered: