I want to generate a dynamic SQL where clause from a Scala collection, such as Map
Example, with a Map("firstName" -> "Chuck", "lastName" -> "Norris") object,
I want to generate the following clause:
where firstName = 'Chuck'
and lastName = 'Norris'
Basically, for the first element in the collection, precede with the where keyword, and for the subsequent ones, precede with and.
I’m really struggling to do this algorithm in Scala, so I’m asking for your help.
Maybe Map isn’t the right collection for this task?
A possible solution is:
The
mapfunction with the format transform key/values intokey = 'value', andmkStringbuild the where clause.