如何在光滑的2.0.1中表示postgres`bygona`类型?

时间:2014-04-07 14:03:43

标签: postgresql scala blob slick bytea

在光滑的文档中,它说java.sql.Blob是支持开箱即用的类型之一,我试图用它来表示bytea列。但是下面的代码给了我一个错误:

import scala.slick.driver.PostgresDriver.simple._
import java.sql.{ Timestamp, Blob }

case class Test(id: Int, last_updated: Timestamp, data: Blob)

class Tests(tag: Tag) extends Table[Test](tag, "tests") {
  def data = column[Blob]("data")
  def last_updated = column[Timestamp]("last_updated")
  def id = column[Int]("id", O.PrimaryKey)
  def * = (id, last_updated, data)
}

错误消息是:

Multiple markers at this line
    - No matching Shape found. Slick does not know how to map the given types. Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported 
     type in a Query (e.g. scala List). Required level: scala.slick.lifted.ShapeLevel.Flat Source type: (scala.slick.lifted.Column[Int], scala.slick.lifted.Column[java.sql.Timestamp], 
     scala.slick.lifted.Column[java.sql.Blob]) Unpacked type: utils.Test Packed type: Any
    - implements scala.slick.lifted.AbstractTable.$times
    - type mismatch; found : (scala.slick.lifted.Column[Int], scala.slick.lifted.Column[java.sql.Timestamp], scala.slick.lifted.Column[java.sql.Blob]) required: 
     scala.slick.lifted.ProvenShape[utils.Test]
    - type mismatch; found : (scala.slick.lifted.Column[Int], scala.slick.lifted.Column[java.sql.Timestamp], scala.slick.lifted.Column[java.sql.Blob]) required: 
     scala.slick.lifted.ProvenShape[utils.Test]

发生了什么以及如何在光滑中正确表示bytea

1 个答案:

答案 0 :(得分:7)

问题与Blob支持无关。由于错误消息表明最常见的原因,表[T]中的T与您的*投影&#34;不匹配。它应该是def * = (id, last_updated, data) <> (Test.tupled, Test.unapply _)

请注意,这仍然不适用于bytea。 Slick的PostgreSQL驱动程序将Blob映射到PotgreSQL的blob类型&#34; lo&#34;延期。您需要Array[Byte]使用bytea