Table: person
Mapped Tables
case class Person(id: Int, name: String, address: Option[Map[String, String]])
trait ReceiptRepositoryImpl {
self: PersonTable with SlickDBComponent =>
def getPersonByCity(city: String): List[Person] = {
personQuery.filter(_.address) // *Here i am unable to convert slick query of select * from person where address -> 'city' = 'Chicago'*
}
}
trait PersonTable {
this: SlickDBComponent =>
import driver.api._
val personQuery: TableQuery[PersonDetailsTable] = TableQuery[PersonDetailsTable]
class PersonDetailsTable(tag: Tag) extends Table[Person](tag, "person") {
def id: Rep[Long] = column[Long]("id", O.PrimaryKey, O.AutoInc)
def name: Rep[String] = column[String]("name")
def address: Rep[Option[Map[String, String]]] = column[Option[Map[String, String]]]("address")
def * = (id, name, address) <> (Person.tupled, Person.unapply)
}
}
select * from person;
id | name | address
----+---------+--------------------
1 | James | "city"=>"Chicago"
1 | Michael | "city"=>"New York"
select * from person where address -> 'city' = 'Chicago';
Please help me to convert above plain query into slick query.
I am using below tech stack with their version.