I have a PostgreSQL table with an enum
, which is created by:
CREATE TYPE file_status AS ENUM ('new', 'uploading', 'queued', 'processing', 'done', 'failed');
and an associated field
CREATE TABLE files ( ...
status file_status NOT NULL,
...
);
With Scala 2.10 and Typesafe Slick 1.0.1, I've created mappings to my Files table that work great with the exception of the status
field, which requires the custom file_status
type, a string.
def status = column[FileStatus]("status")
I've been playing with Slick's TypeMapper, but can't quite figure out how to get it to work:
sealed trait FileStatus
implicit val fileStatusMapper: TypeMapper[String] = base[FileStatus, String](
s => s.toString,
f => f(FileStatus)
)
I get the error: type mismatch; found : models.Files.FileStatus.type required: Int
Why is an Int required? Is it because of the TypeMapper? I have also tried
...
f => f.toString
// type mismatch; found : String required: models.Files.FileStatus
f => f
// type mismatch; found : String required: models.Files.FileStatus
Thank you for any pointers in helping me understand this mapping.
Quoting from the docs (http://slick.typesafe.com/doc/1.0.1/lifted-embedding.html#user-defined-functions-and-types):
Adapting this to file status:
Update:
Another, less redundant, but possibly also less clear version:
Slick 3.x version: