【发布时间】:2016-09-07 13:42:51
【问题描述】:
我正在使用 scala play 2、slick 和 postgresql 作为数据库。我的功能之一是
def getAllCustomersWithAccount: Future[Seq[CustomerDetail]] = {
val joinException = for {
(customer, account) <- table join accountTable on (_.id === _.id)
} yield (customer.id, account.name, account.phone, account.email, customer.status, customer.balance, customer.payable, customer.created, customer.updated)
val result = db.run(joinException.result)
result.map(row => row.map(x => CustomerDetail(x._1, x._2, x._3, x._4, x._5, x._6, x._7, x._8, x._9)))
}
此代码不起作用。问题是创建和更新客户的属性。也就是说 customer.created 和 customer.updated 是 Rep[Option[Instant]] ,它是日期时间。如果我转义这两列(customer.created 和 customer.updated),那就没问题了。那就是
def getAllCustomersWithAccount: Future[Seq[CustomerDetail]] = {
val joinException = for {
(customer, account) <- table join accountTable on (_.id === _.id)
} yield (customer.id, account.name, account.phone, account.email, customer.status, customer.balance, customer.payable)
val result = db.run(joinException.result)
result.map(row => row.map(x => CustomerDetail(x._1, x._2, x._3, x._4, x._5, x._6, x._7)))
}
此代码运行良好。我想将 Rep[Option[Instant]] 转换为 Rep[Option[String]]。我该怎么做?
【问题讨论】: