我正在使用scala play 2,slick和postgresql作为数据库。我的一个功能就像我如何将Rep [Option [Instant]]转换为scala中的Rep [Option [String]]
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]]。我怎样才能做到这一点?
感谢您回答。你能否清楚你的答案?我该如何解决这个问题?我只想将Rep [Option [Instant]]转换为'Rep [Option [String]]' –
提供从'Instant'到'String'的转换。隐式def instantMapping:BaseColumnType [Instant] = MappedColumnType.base [Instant,String](....) – pamu
你确定有作品???????????你可以显示完整的代码吗? –