Is this a bad idea: ```inline fun <reified T : ...
# komapper
d
Is this a bad idea:
Copy code
inline fun <reified T : Any> literal(value: T): ColumnExpression<T, T> {
        val operand = Operand.SimpleArgument(T::class, value)
        return columnExpression(T::class, "literalObject", listOf(operand)) {
            visit(operand)
        }
    }
to use in selectAsXXX functions... I need to put in literals when I use that with
Copy code
QueryDsl.insert(...).select { 
... // here often I need these literals like value classes, or enums... I use a query with selectAsXXX
}
It doesn't seem to work... im trying to use it for an enum field but it gives me an illegal state exception that the datatype is not found for the type... from Defaultr2dbcdataoperator.getdatatype()
t
Assuming there is the following Enum type, entity class, and function.
Copy code
enum class Color {
    RED, BLUE
}

@KomapperEntity
@KomapperProjection
data class Box(
    @KomapperId
    @KomapperAutoIncrement
    val id: Int = 0,
    @KomapperEnum(type = EnumType.NAME)
    val color : Color,
)

// ColumnExpression for a generic Enum type
fun <E : Enum<E>> bindEnum(expression: ColumnExpression<E, *>, value: E): ColumnExpression<E, *> {
    val operand = Operand.Argument(expression, value)
    return columnExpression(expression,"bindEnum", listOf(operand)) {
        visit(operand)
    }
}
Use the above
bindEnum
function as follows:
Copy code
database.runQuery {
    QueryDsl.insert(b).select {
        QueryDsl.from(b).selectAsBox(id = b.id, color = bindEnum(b.color, Color.BLUE))
    }
}
d
Thanks! That seems to work... it might be nice to add that to the next version...?