Is there something like Django's "Q" object?
# exposed
t
Is there something like Django's "Q" object?
t
I'm not aware of Django, so could you provide use-case where and how you want to use optional parameters?
t
Let's say you have a REST resource that might be filtered via get parameters, in any arbitrary combination. What's the preferred exposed approach to building this where clause/select?
Django has a "Q" object to dynamically build these logical conditions https://docs.djangoproject.com/en/1.7/ref/models/queries/#q-objects
t
Copy code
val baseCondition = Op.build { FooTable.type eq type }
val extendedCondition = baseCondition and when(type) {
    type1 -> Op.build { FooTable.col1 eq "bar" }
   else -> Op.build {} 
}
t
Cool, I like that. Thanks
t
Another way is to use
adjustWhere
on Query.
Copy code
val baseQuery = FooTable.select { FooTable.type eq type } 
if (cond()) {
   baseQuery.adjustWhere { 
      this!!.and FooTable.col1 eq "bar"
   }
}