Используя Slick 3 и PostgreSQL, мне нужно запросить и обновить таблицу с столбцом типа enum:
create type WeekDay as ENUM('sun','mon','tue','wed','thu','fri','sat');
create table shifts(
id serial PRIMARY KEY,
user_id INTEGER,
branch_id INTEGER,
start INTEGER,
duration INTEGER,
day WeekDay
-- foreign keys etc.
);
Я пытался использовать Slick's MappedColumnType[java.time.DayOfWeek,String]
, но это не удовлетворяет * Средство проверки типа 1013 * (TBH, по праву):
org.postgresql.util.PSQLException: ERROR: column "day" is of type weekday but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
Position: 92
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2412)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2125)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:297)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:428)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:354)
at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:169)
at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:136)
at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeUpdate(ProxyPreparedStatement.java:61)
at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeUpdate(HikariProxyPreparedStatement.java)
at slick.jdbc.JdbcActionComponent$InsertActionComposerImpl$SingleInsertAction.$anonfun$run$15(JdbcActionComponent.scala:520)
Класс таблицы:
class ShiftTable(tag:Tag) extends Table[Shift](tag, "shifts") {
import Mappers.dayOfWeekMapper
def id = column[Long]("id", O.AutoInc, O.PrimaryKey)
def userId = column[Long]("user_id")
def branchId = column[Long]("branch_id")
def start = column[Int]("start")
def duration = column[Int]("duration")
def day = column[DayOfWeek]("day") // <- problematic column
// keys etc/
def * = (id, userId, branchId, start, duration, day) <> (Shift.tupled, Shift.unapply)
}
Как сопоставить значение Scala с пользовательским типом PostgreSQL?