Using function to update case class value in scala Quill

402 Views Asked by At

I have following case class

case class Tag(key: String, value: String, modifiedDate: Date)

And I have a data access object that looks like this:

class TagDao(implicit val ec: ExecutionContext, val ctx: PostgresAsyncContext[SnakeCase]) {
  def update(tag: Tag): Future[Int] = 
    performIO(
      runIO(
        quote {
          query[Tag]
            .filter(_.id == tag.id)
            .update(lift(tag))
            .returning(_.id)
        }
      )
    )
}

I want modifiedDate field of Tag in update method to be replaced by CURRENT_TIMESTAMP. How can it be done?

One alternative is before updating I set the modifiedDate manually in the code

1

There are 1 best solutions below

0
On BEST ANSWER

try to use copy method from case class object and pass new Date contained current date:

def update(tag: Tag): Future[Int] = 
    performIO(
      runIO(
        quote {
          query[Tag]
            .filter(_.id == tag.id)
            .update(
              lift(tag.copy(modifiedDate = new Date()))
            )
            .returning(_.id)
        }
      )
    )