Created
March 14, 2019 07:00
-
-
Save xhoong/82d05fc6d96cf47ca3568678e9ecab23 to your computer and use it in GitHub Desktop.
Mapping plain SQL in Slick to a case class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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