我有一个MySQL表映射为

class HealthReport(tag: Tag) extends Table[(Int, Int, Int, String, Timestamp, Blob)](tag, "LogProcessorHealthReport") {

  def id = column[Int]("id")
  def usersId = column[Int]("Users_Id")
  def tenantId = column[Int]("Tenant_Id")
  def ecId = column[String]("EcId")
  def reportedOn = column[Timestamp]("ReportedOn")
  def healthInfo = column[Blob]("HealthInfo")

  def * = (id, usersId, tenantId, ecId, reportedOn, healthInfo)
}


我想阅读healthInfo的内容,该怎么办?

谢谢

最佳答案

光滑2:

import slick.driver.MySQLDriver.simple._

val db = Database.forConfig("db")
val fourthHealthInfo: Option[Blob] = db withSession { implicit session =>
  TableQuery[HealthReport].filter(_.id === 4).map(_.healthInfo).list.headOption
}
val healthInfos: List[Blob] = db withSession { implicit session =>
  TableQuery[HealthReport].map(_.healthInfo).list
}


圆滑的3:

import slick.driver.MySQLDriver.api._

val db = Database.forConfig("db")
val fourthHealthInfo: Future[Option[Blob]] = db run {
  TableQuery[HealthReport].filter(_.id === 4).map(_.healthInfo).result.headOption
}
val healthInfos: Future[Seq[Blob]] = db run {
  TableQuery[HealthReport].map(_.healthInfo).result
}

10-07 23:57