Skip to content

Instantly share code, notes, and snippets.

@xhoong
Created March 14, 2019 07:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xhoong/82d05fc6d96cf47ca3568678e9ecab23 to your computer and use it in GitHub Desktop.
Save xhoong/82d05fc6d96cf47ca3568678e9ecab23 to your computer and use it in GitHub Desktop.
Mapping plain SQL in Slick to a case class
//https://softwaremill.com/comparing-scala-relational-database-access-libraries/
case class MetroSystemWithCity(metroSystemName: String, cityName: String,
dailyRidership: Int)
implicit val getMetroSystemWithCityResult = GetResult(r =>
MetroSystemWithCity(r.nextString, r.nextString, r.nextInt))
val query = sql"""SELECT ms.name, c.name, ms.daily_ridership
FROM metro_system as ms
JOIN city AS c ON ms.city_id = c.id
ORDER BY ms.daily_ridership DESC""".as[MetroSystemWithCity]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment