【发布时间】:2017-05-09 20:19:37
【问题描述】:
我有一个来自 Slick (3.1.1) 的代码生成模型,我知道我可以用它做以下事情,例如
val action = sql"""SELECT * FROM ${User.baseTableRow.tableName}""".as[UserRow].headOption
db.run(action)
但现在我对 Slick 有了更多的了解,我有以下查询:
val selectAction = (for {
linkedAccount <- LinkedAccount
user <- User if user.id === sourceUser.id && user.id === linkedAccount.userId
} yield (targetUser.id, linkedAccount.providerKey, linkedAccount.providerPassword, linkedAccount.modified)).
result.map(_.map(LinkedAccountRow.tupled))
我可以将结果元组(targetUser.id, linkedAccount.providerKey, linkedAccount.providerPassword, linkedAccount.modified) 映射到适当的案例类LinkedAccountRow 的唯一方法是使用这个丑陋的.map(_.map(LinkedAccountRow.tupled)) ...并且应该有一个更优雅的方法来使用生成的<> ,tupled 还是?
【问题讨论】:
-
.map(_.map(LinkedAccountRow.tupled))有什么丑陋之处?