Dynamic comparisons

12 views
Skip to first unread message

Richard Dallaway

unread,
Apr 22, 2016, 12:32:02 PM4/22/16
to Slick / ScalaQuery
Hello.

I've been constructing queries from dynamic (user-supplied) data, where the type of comparison itself is dynamic. 

E.g., I want to turn a request such as "/messages?field=id&comparison=equals&value=7" into a query of the form messages.filter(_.id === 7).  For a limited set of comparisons (equals, like, in, greater-than...).

That's totally doable, I have a way to do it. There's an example runnable project right here:  https://github.com/d6y/dynamic-filter

It works, but there's a bit of code involved, and it doesn't support optional columns automatically.

Anyone have a better way? 
Or want to suggest clues/pointers for improvements or alternative approaches?

Cheers
Richard

Reply all
Reply to author
Forward
0 new messages