Skip to content

Suggestion: Support for in-line row mapper #4

@arvearve

Description

@arvearve

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions