我正在使用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
你確定有作品???????????你可以顯示完整的代碼嗎? –