gpt4 book ai didi

mysql - Slick:如何从 MySQL 读取 Blob?

转载 作者:行者123 更新时间:2023-11-30 22:20:08 25 4
gpt4 key购买 nike

我有一个 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
}

关于mysql - Slick:如何从 MySQL 读取 Blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36877135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com