here's some context:
# getting-started
h
here's some context:
Copy code
class WhereClause(
    var conditional: String = emptyString,
    var table: DatabaseTable = DatabaseTable.NONE,
    var postgreFunction: String = emptyString,
    var comparison: String = emptyString,
    var fieldName: String = emptyString,
    var tableName: String = table.tableName
) {
    override fun toString(): String {
        val whereClause = StringBuilder(SPACE)

        if (conditional.isNotEmpty)
            whereClause.append(conditional).append(SPACE)

        if (postgreFunction.isNotEmpty && postgreFunction !== ANY)
            whereClause.append(postgreFunction).append(OPEN_FUNCTION)

        if (tableName.isNotEmpty)
            whereClause.append(tableName).append(TABLE_FIELD_SEPARATOR)

        whereClause.append(fieldName)

        if (postgreFunction.isNotEmpty && postgreFunction !== ANY)
            whereClause.append(CLOSE_FUNCTION)

        whereClause.append(SPACE).append(comparison)

        if (comparison !== IS_NULL && comparison !== IS_NOT_NULL) {
            whereClause.append(SPACE)

            if (postgreFunction === ANY)
                whereClause.append(postgreFunction).append(OPEN_FUNCTION)

            whereClause.append(PARAMETER_PLACEHOLDER)

            if (postgreFunction === ANY)
                whereClause.append(CLOSE_FUNCTION)
        }

        return whereClause.toString()
    }

    fun validate(initialClause: Boolean): Boolean =
        when {
            !initialClause && conditional.isEmpty -> false
            fieldName.isBlank                     -> false
            comparison.isEmpty                    -> false
            else                                  -> true
        }

    companion object {
        operator fun invoke(init: WhereClause.() -> Unit) = WhereClause().apply(init)
    }
}
well, didn't want to flood the channel with an unnecessary wall of text, but it's kinda unreadable with word wrap like this...
g
What about using gist or something like that?
s
lol, that’s what snippets are for
h
🤷
s
regardless, from what I can tell, kwargs in the constructor would still fit your use case
since whomever’s looking to build the clause would still pick the fields they need and the default values would populate the fields they don’t
but it’s your code, you’ve got the 30,000 foot view
h
i'm trying to learn as much as i can, and practicing. this code isn't vital, but i'm always open to better ideas