The slick documentation explains how to perform an update operation on a specific column, but doesn’t include any examples of updating the entire record.
Below is a tiny example of how to do that.
Let’s assume we have a mapped table that uses a custom type Customer:
import scala.slick.driver.MySQLDriver.simple._
case class Customer(id: Option[Long], firstName: String, lastName: String)
object Customers extends Table[Customer]("customers") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def firstName = column[String]("first_name")
def lastName = column[String]("last_name")
def * = id.? ~ firstName ~ lastName <> (Customer, Customer.unapply _)
}The simplest way to update the entire Customer record is to call the where method on the Table object, then execute update with the Customer object as the argument. For example,
...
val updatedCustomer = Customer(Some(1L), "First", "Last")
...
Customers.where(_.id === updatedCustomer.id.get).update(updatedCustomer)
...Hope you find it helpful
