6

我有以下 postgres 列定义:

record_time TIMESTAMP WITHOUT TIME ZONE DEFAULT now()

我如何将它映射到光滑?请考虑到我希望映射now()函数生成的默认值

IE:

def recordTimestamp: Rep[Date] = column[Date]("record_time", ...???...)

是否应该在...???...当前所在的位置进行任何额外的定义?

编辑 (1)

我不想使用

column[Date]("record_time", O.Default(new Date(System.currentTimeMillis()))) // or some such applicative generation of the date column value
4

3 回答 3

4

我发现一个博客解释说你可以使用以下内容:

// slick 3
import slick.profile.SqlProfile.ColumnOption.SqlType
def created = column[Timestamp]("created", SqlType("timestamp not null default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP"))

// slick 3
def createdAt = column[Timestamp]("createdAt", O.NotNull, O.DBType("timestamp default now()"))

见:http: //queirozf.com/entries/scala-slick-dealing-with-datetime-timestamp-attributes

于 2016-10-11T00:37:05.667 回答
2

光滑 3 示例

import slick.driver.PostgresDriver.api._
import slick.lifted._
import java.sql.{Date, Timestamp}

/** A representation of the message decorated for Slick persistence
  * created_date should always be null on insert operations.
  * It is set at the database level to ensure time syncronicity
  * Id is the Twitter snowflake id. All columns NotNull unless declared as Option
  * */
class RawMessages(tag: Tag) extends Table[(String, Option[String], Timestamp)](tag, Some("rti"), "RawMessages") {
  def id = column[String]("id", O.PrimaryKey)
  def MessageString = column[Option[String]]("MessageString")
  def CreatedDate = column[Timestamp]("CreatedDate", O.SqlType("timestamp default now()"))
  def * = (id, MessageString, CreatedDate)
}
于 2016-11-22T22:37:53.907 回答
2

我想这还不支持。这是问题:https ://github.com/slick/slick/issues/214

于 2015-08-03T13:55:39.273 回答