-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
In many cases it would be nice to have an overload for queryOf<T>() / actionReturing<T>() that takes an extractor function / row mapper, e.g.
data class Statement {
// ...
inline fun <reified T> queryOf((ResultSet) -> T?): Query<T> = TODO()
}Some times it’s nice to be allowed to access “under the hood”
If i understand correctly this would let you bypass the kotlinx.serialization loop and would be useful in complex cases where you would otherwise have to tailor your entity data classes a lot in order to make things work. E.g. custom Serializers, @contextual and @SerialName annotations,
Example envisioned usage:
// Business layer model
data class Member(val id: String, val name: String?, val createdAt: ZonedDateTime)
// No need for @Serializable entity class with @Contextual on dates, etc.
val query = Sql("...").queryOf<Member> { row -> Member(
row.int("id"),
row.stringOrNull("name"),
row.zonedDateTime("created_at")
)
}
query.runOn(db)This suggestion is inspired by Kotliquery's implementation.
References:
Metadata
Metadata
Assignees
Labels
No labels