Thread
#exposed
    t

    tmseiler

    4 years ago
    Is there something like Django's "Q" object?
    tapac

    tapac

    4 years ago
    I'm not aware of Django, so could you provide use-case where and how you want to use optional parameters?
    t

    tmseiler

    4 years ago
    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
    tapac

    tapac

    4 years ago
    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

    tmseiler

    4 years ago
    Cool, I like that. Thanks
    tapac

    tapac

    4 years ago
    Another way is to use
    adjustWhere
    on Query.
    val baseQuery = FooTable.select { FooTable.type eq type } 
    if (cond()) {
       baseQuery.adjustWhere { 
          this!!.and FooTable.col1 eq "bar"
       }
    }