简体   繁体   中英

Using function to update case class value in scala Quill

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

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)
        }
      )
    )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM