Advertisement
Guest User

Untitled

a guest
May 14th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. package com.github.jacoby6000.query.dsl.weak
  2.  
  3. import org.specs2._
  4.  
  5. import scalaz.concurrent.Task
  6. import com.github.jacoby6000.query.interpreters._
  7. import com.github.jacoby6000.query.interpreters.sqlDialects.postgres
  8. import com.github.jacoby6000.query.dsl.weak.sql._
  9. import doobie.imports._
  10.  
  11. /**
  12. * Created by jbarber on 5/14/16.
  13. */
  14. class SqlDSLSimpleSelectTest extends Specification { def is = s2"""
  15.  
  16. A simple query should
  17. return some results $result
  18. """
  19.  
  20. val xa = DriverManagerTransactor[Task](
  21. "org.postgresql.Driver", "jdbc:postgresql:world", "postgres", "postgres"
  22. )
  23.  
  24. // the below should compile.
  25. case class CountryCodePair(gnp: Int, code: String)
  26.  
  27. def result =
  28. (
  29. select(
  30. (path"c1.gnp" ++ 5) as "c1name",
  31. p"c1.code",
  32. p"c2.gnp",
  33. p"c2.name"
  34. ) from (
  35. p"country" as "c1"
  36. ) innerJoin (
  37. p"country" as "c2"
  38. ) on (
  39. path"c2.code" === func"reverse"(path"c1.code")
  40. )
  41. ).build
  42. .query[(CountryCodePair, CountryCodePair)]
  43. .list
  44. .transact(xa)
  45. .unsafePerformSync must haveSize(12)
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement