在 Slick table 定义中使用数据库函数 - 怎么样?

Using database functions in Slick table definitions - how?

有没有人成功使用 Slick(我目前使用的是 3.0.0-RC3,最新的可用版本)来生成包含 DB 特定函数的 table 定义?如果可以,如何实现?

示例:我在 Postgres 中有一列定义如下:

"request_date" timestamp default now(),

我尝试(未成功)在 Slick DDL 中描述。

第一次尝试:

def requestDate = column[Option[DateTime]]("request_date", O Default "now()")

当然,这被拒绝了:

[error] <path-to-file>: type mismatch;
[error]  found   : String("now()")
[error]  required: Option[org.joda.time.DateTime]
[error]     def requestDate = column[Option[DateTime]]("request_date", O Default "now()")

好的,我已经尝试定义一个 SimpleFunction(我已经有了 DateTime 转换器):

val dbNow = SimpleFunction.nullary[DateTime]("now")
def requestDate = column[Option[DateTime]]("request_date", O Default dbNow)

产生了另一个错误:

[error] <path-to-file>: type mismatch;
[error]  found   : slick.lifted.Rep[org.joda.time.DateTime]
[error]  required: Option[org.joda.time.DateTime]
[error]     def requestDate = column[Option[DateTime]]("request_date", O Default dbNow)

我也试过SimpleLiteral[DateTime]("now()"),结果也是类似的错误。 (删除选项也无济于事)。

如有任何想法,我们将不胜感激。有点郁闷,这么简单的东西,好像不容易得到...

目前不支持:https://github.com/slick/slick/issues/214。您需要使用普通 SQL

相应地更改 table