I have a MySQL 5.7 database with several tables that store UUIDs in columns with a VARCHAR data type. I am trying to convert our code base to use Slick 3.1.1, but I have to deal with the problem of converting UUID to String. This is the definition of my column:
def myCol: Rep[UUID] = column[UUID]("myCol", SqlType("VARCHAR"))
When I run queries, I get exceptions like this:
Got the exception java.sql.SQLException: Incorrect string value: '\xDA\xFD\xDAuOL...' for column 'myCol' at row 1
From what I understand, Slick suggests that UUIDs should be stored as binary column types, so I tried to implicitly convert to String using:
implicit val uuidToString = MappedColumnType.base[UUID, String](_.toString, UUID.fromString) def myCol: Rep[UUID] = column[UUID]("myCol", SqlType("VARCHAR"))(uuidToString)
This works for insertion, but when I select values ββwith myCol
, the results become empty. Does anyone know how I can force Slick to use VARCHAR instead of BINARY (16) to convert the data?
EDIT:
With an implicit query, this query does not return any results:
db.run { table.filter(_.myCol
But it does:
db.run { table.result }.map(_.filter(_.myCol == val))
EDIT2:
I have a small project with a demo: https://github.com/nmatpt/slick-uuid-test
source share