如何在Scala Slick中使用表映射来映射Blob

时间:2018-08-16 14:50:08

标签: scala intellij-idea slick

嗨,我创建了一个班

case class HorseProfile(HorseID: Int,HorsePicUrl:Blob)
case class HorseProfileData(HorseID: Int, HorsePicUrl:Blob)

然后我想用表列之类来映射此类

object HorseForm1 {

  val form = Form(
    mapping(
      "HorseID" -> number,
      "HorsePicUrl" ->nonEmptyText ,


    )(HorseProfileData.apply)(HorseProfileData.unapply)
  )
}

在HorsePicUrl上,我传递了nonEmptyText,但我已将其定义为BLOB

这是我为此类提供的完整代码,因为我也正在调用存储过程,但无法获得带有正确标头的响应

class HorseProfilePicDef(tag: Tag) extends Table[HorseProfile](tag, "Horse_profile_image") {

  def HorseID = column[Int]("horseid")
  def HorsePicUrl = column[Blob]("horseimage")
  //def HorsePics = column[Blob]("horseimage")

 // def * = (HorseID, HorsePics)
  override def * =
    (HorseID, HorsePicUrl) <>(HorseProfile.tupled, HorseProfile.unapply)
}

object HorseProfilePics {
  val dbConfig = Database.forURL("jdbc:mysql://localhost:3306/equineapp?user=root&password=123456", driver = "com.mysql.jdbc.Driver")
  //val dbConfig1 = dbConfig.get[JdbcProfile](Play.current)
  val horsepics = TableQuery[HorseProfilePicDef]
  //val scopeIdentity = SimpleScalarFunction.nullary[Long]("scope_identity")
  //val insertQuery = users returning users.map(_.HorseID) into ((users, id) => users.copy(HorseID = id))

  def HorseImage(HorseId : Int): Future[String] = {


    val setup1 = sql"call HorsePrfile ($HorseId);".as[(Int, String)]
    val res = Await.result(dbConfig.run(setup1), 1000 seconds)
    dbConfig.run(setup1).map(res => res.toString).recover {
      case ex: Exception => ex.getCause.getMessage


    }
  }

0 个答案:

没有答案