![](/img/trans.png)
[英]How to save auto-generated primary key value into second column right after inserting new row
[英]slick 3 auto-generated - default value (timestamp) column, how to define a Rep[Date] function
我有以下postgres列定義:
record_time TIMESTAMP WITHOUT TIME ZONE DEFAULT now()
我如何將其映射到光滑? 請考慮我希望映射now()
函數生成的默認值
即:
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
我發現一個博客解釋說你可以使用以下內容:
// 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
我想這還不支持。 這是問題: https : //github.com/slick/slick/issues/214
光滑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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.