I'm new to Scala and slick. My use case is like this. I have name, school, and gradeList. Name and school are string values. GradeList is a map where i have subject as key and grade as value. I need to write a search query for this scenario. And also name and school columns are in one table and subject and grade columns are in another table. So i need to join them too. I can make the query work when a string value is given for subject and grade. But I cannot figure out a way to iterate through the map where all the subject, grade key pair is considered for the query.
So far my code is as below.
val innerJoin = for {
(a, _) <- nameQuery.join(gradeQuery).on(_.id === _.studentId)
.filter(result =>
(result._1.name.toLowerCase.like(s"%$name%") &&
(result._1.school.toLowerCase.like(s"%$school%") &&
result._2.subject.toLowerCase.like(s"%$subject%") &&
result._2.grade.toLowerCase.like(s"%$grade%"))
} yield a
innerJoin.distinctOn(_.id).take(limit).result
name, school, gradeList are my parameters to the function.
Can someone help me in finding a solution for this? Thanks in advance.