Reputation: 2847
In slick's documentation it's said that java.sql.Blob
is one of types supported out of the box and I'm attempting to use it to represent bytea
column. But the following code gives me an error:
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)
}
The error message is:
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]
What is going on and how can I correctly represent bytea
in slick?
Upvotes: 2
Views: 1766
Reputation: 1406
The problem is not related to Blob
support. As the error message suggests as the most common reason, "T in Table[T] does not match your * projection". It should be def * = (id, last_updated, data) <> (Test.tupled, Test.unapply _)
.
Note that this will still not work for bytea
. Slick's PostgreSQL driver maps Blob
to the blob type from PotgreSQL's "lo" extension. You need to use Array[Byte]
for bytea
.
Upvotes: 7