0

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

Shamshad Alam
  • 1,684
  • 3
  • 19
  • 31

1 Answers1

1

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)
        }
      )
    )
Boris Azanov
  • 4,408
  • 1
  • 15
  • 28