Thread
#exposed
    s

    spand

    3 years ago
    Is it possible to create my own operator on
    SqlExpressionBuilder
    somehow ?
    tapac

    tapac

    3 years ago
    With
    Expression<*>
    as a receiver? I guess it's impossible as you need to have 2 receivers on a single function. Why do you need that? To reduce function scope?
    s

    spand

    3 years ago
    I wanted to make my own helper functions.. ie.
    inInterval
    that checks a column c is: interval.start <= c && c < interval.end
    tapac

    tapac

    3 years ago
    The only thing is extension on
    Expression<DateTime?>.inInterval(..)
    but it will be available out of
    SqlExpressionBuilder
    scope.
    s

    spand

    3 years ago
    Yeah that what I ended up doing and importing
    greaterEq
    , and
    less
    . Would just be nice to have it encapsulated like the rest.
    Maybe it ought to be a language proposal to have multiple extension receivers.
    tapac

    tapac

    3 years ago
    Not sure what this is exactly about you need,
    s

    spand

    3 years ago
    Thanks. Will take a look
    tapac

    tapac

    3 years ago
    I found interesting approach here (https://discuss.kotlinlang.org/t/declare-member-extensions-outside-the-class/6759/6?u=tapac)
    val SqlExpressionBuilder.inInterval: ExpressionWithColumnType<DateTime?>.(Interval) -> Expression<Boolean> get() = { interval ->
        val expr = this
        (expr greater interval.start) and (expr less interval.end) 
    
    }
    
    fun main() {
        Op.build {
            val expr = dateLiteral(DateTime.now())
            expr.inInterval(3)
        }
    }
    s

    spand

    3 years ago
    That is an interesting approach 😉
    We only use infix however so I think I prefer the fun