While giving JDBI a try for the first time with the Postgres, Kotlin, KotlinSqlObject and Jackson2 plugins enabled, I half hoped I might be able to write an SqlObject interface like so:
data class Resource(val id: String, val name: String)
interface ResourceDao {
@SqlUpdate("insert into resources (id, resource, version, created_at) values(:resource.id, :resource, 1, :now)")
@Timestamped
fun insert(@Json resource: Resource)
}
The `resource` column is a Postgres `jsonb` type. But as it turns out, and it's probably no surprise to those that know the ins and outs of JDBI, it doesn't work as I hoped it would. The `insert` method results in a "Parameter name `
resource.id` not found" exception.
So now I'm wondering if there's a way that I might write this interface, that isn't immediately obvious to me, such that an API consumer wouldn't have to explicitly pass the ID value and the resource object in two separate parameters.