Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. protected def locationGroupLinkTable: Query[(Rep[LocationGroupId], Rep[LocationId]), (LocationGroupId, LocationId), Seq] = {
  2.  
  3. import common.Contexts.simpleDbLookups
  4. import profile.api._
  5.  
  6. val rawData: Seq[LocationGroupLink] = Await.result(locationGroupLinkRepository.all, Duration.Inf)
  7.  
  8. val tableRows: Seq[Query[(ConstColumn[LocationGroupId], ConstColumn[LocationId]), (LocationGroupId, LocationId), Seq]] = {
  9. rawData.map { link =>
  10. Query(link.groupId, link.merchantId)
  11. }
  12. }
  13.  
  14. val subQuery: String = rawData.map { link =>
  15. (link.groupId.value, link.merchantId.value)
  16. }.map { case (locationGroupId, merchantId) =>
  17. s"SELECT $locationGroupId AS L, $merchantId AS M FROM DUAL"
  18. }.mkString(" UNION ")
  19.  
  20. val sql: String = s"SELECT L, M FROM ($subQuery)"
  21.  
  22. val q: SqlStreamingAction[Vector[(LocationGroupId, LocationId)], (LocationGroupId, LocationId), Effect] = {
  23. sql"""#$sql""".as[(LocationGroupId, LocationId)]
  24. }
  25.  
  26. q
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement