기본적으로 Slick은 O.AutoInc
플래그가있는 열의 값을 무시하고 데이터베이스가 삽입 작업 중에 해당 값을 채울 수 있도록합니다.Slick에서 AutoInc 열의 값을 명시 적으로 지정하는 방법
가끔은 자동 증가 열에 대한 특정 값을 삽입해야하지만 Slick은 여전히이를 무시합니다. 그것을 할 방법이 있습니까?
나는 두 번째 테이블 정의를 만들 수 있습니다. O.AutoInc
플래그가 없지만보다 우아한 방법을 찾고 있습니다.
업데이트
: 당신이Option
알로
id
필드를 표시하면
case class Transaction (id: Long, timestamp: LocalDateTime, comment: Option[String])
class Transactions(tag: Tag) extends Table[Transaction](tag, "tx") {
implicit val localDTtoDate = MappedColumnType.base[LocalDateTime, Timestamp] (
l => Timestamp.valueOf(l),
d => d.toLocalDateTime
)
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def timestamp = column[LocalDateTime]("ts")
def comment = column[Option[String]]("comment")
def * = (id, timestamp, comment) <> ((Transaction.apply _).tupled, Transaction.unapply)
}
당신은이 작업을 수행 할 수는'*'-projection이 ID를 사용 기둥. 테이블 정의를 복사하여 붙여 넣을 수 있습니까? – jkinkead
@jkinkead 예! – akashihi