I have this function in my DB layer :
suspend inline fun <T : Any> query(stmt: String, vararg params: Any?, crossinline transform: (Row) -> T): List<T>? = dbQuery {
var result: List<T>? = null
using(sessionOf(dataSource)) { session ->
result = session.run(queryOf(stmt, params)
.map { transform(it) }
.asList
)
}
result
}
And then I simply call from my controller :
db.query<User>("SELECT * FROM users where name = ?, "John")
For some reason, the params here make the query crash, because :
org.postgresql.util.PSQLException: Cannot cast an instance of [Ljava.lang.Object; to type Types.ARRAY
at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:1004)
When I call the code like this however :
result = session.run(queryOf(stmt, "John")
it works perfectly.
(i.e - When using hardcoded "John" instead passing params
)
Only when I pass the varargs through a function it starts crashing.