trying to implement this function but its from an ...
# exposed
k
trying to implement this function but its from an old exposed version, doesnt work anymore
Copy code
class PostgreSQLJsonValue<T>(
    private val expr: Expression<*>,
    override val columnType: ColumnType,
    private val jsonPath: List<String>
) : Function<T>(columnType) {
    override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder {
        append("(")
        append(expr)
        append("${jsonPath.joinToString { it }})::${columnType.sqlType()}")
    }
}
what is the new way to implement the above? im referencing this code from here https://brightinventions.pl/blog/exposed-in-your-project-json-support/ so i can do something like this (jsonb query)
Copy code
fun findByNickname(nickname: String): FoundPersonWithAddressDto? = transaction {
    PersonEntity
        .find { PersonTable.details.jsonValue<String>("->>'nickname'") eq nickname }
        .firstOrNull()
        ?.load(PersonEntity::addresses)?.toFoundPersonWithAddressDto()
}
c
Hi @Karl Azzam You could try this:
Copy code
class PostgreSQLJsonValue<T>(
    private val expr: Expression<*>,
    columnType: ColumnType<T & Any>, // <---
    private val jsonPath: List<String>
) : Function<T>(columnType) {
    override fun toQueryBuilder(queryBuilder: QueryBuilder) = queryBuilder {
        append("(")
        append(expr)
        append("${jsonPath.joinToString { it }})::${columnType.sqlType()}")
    }
}
k
thanks @Chantal Loncle
👍 1