I have a query joining many tables. I would like to be able to parameterize which fields to retrieve (sometimes complex SQL Postgis functions). Let say that the initial request is constructed as follows:
def buildQuery() = for {
c <- coffees if c.price > 9.0
s <- c.supplier
} yield (c.name, s.name)
Now I want one of the received values to depend on my parameter, so the example will look like this:
val param = true
def buildQuery() = for {
c <- coffees if c.price > 9.0
s <- c.supplier
} yield (c.name, if (param) s.name else null)
Such code will not work; internal Slick objects raise a NullPointerException. Is there a reasonable way to dynamically build part of the yield based on input parameters?
source
share