I'm pretty new to Exposed. I'm trying to build a b...
# exposed
d
I'm pretty new to Exposed. I'm trying to build a base repository class with a find function where I can pass in the name of a data class property and I find the column searching lowercase, kebab, and snake. My column find function returns a
Column<*>
type, though, which cannot be used in a
.where
as there don't seem to be extension functions like
.eq
defined for
Column<*>
. What is the proper way to do this? My column finder function is:
Copy code
fun findColumn(table: Table, column: String): Column<*> =
        table.columns.find {
            it.name.lowercase() == column.lowercase() ||
                    it.name.lowercase() == column.toSnakeCase() ||
                    it.name.lowercase() == column.toKebabCase()
        } ?: error("Could not find column $column in table ${table.tableName}")
m
I think you can cast the column to Column<Any?>, then extension functions like eq become available. Depending on your use case, a better way might be to use reflection and if possible assume explicit typing based on the type of property of your data classes (TextColumn for Strings etc.). If you want to execute type-specific functions (LIKE etc.), you also might want to think about using
.castTo(columnType)
which would make sure the operation will work in most cases on da DB level as well as being “available” in Exposed because of proper typing of the column.