https://kotlinlang.org logo
Title
r

Robert Jaros

02/07/2022, 7:41 PM
I've just accidentally found this impressive project, I've never even heard about before - https://github.com/komapper/komapper. Definitely worth checking when someone is looking for a Kotlin ORM.
👍🏻 1
👍 10
t

Toshihiro Nakamura

02/08/2022, 12:49 PM
Hi, I'm the author of the project. Thank you for bringing this up. I hope you will try Komapper. I'm looking forward to your feedback.
2
r

Robert Jaros

02/08/2022, 1:34 PM
Hi, @Toshihiro Nakamura As the reference docs are unfortunately not in English (yet?), could you please tell me if there is a way to call native SQL queries in komapper?
t

Toshihiro Nakamura

02/08/2022, 11:00 PM
Komapper supports SQL templates. Using this feature, you can write the following:
val sql = "select * from address where street = /*street*/'test'"
val query = QueryDsl.fromTemplate(sql).bind(
    object {
        val street = "STREET 10"
    }
).select { row ->
    Address(
        row.asInt("address_id")!!,
        row.asString("street")!!,
        row.asInt("version")!!
    )
}
val list: List<Address> = db.runQuery(query)
The above code will issue the following SQL:
select * from address where street = ?
The code in the link may be helpful: https://github.com/komapper/komapper/blob/main/integration-test-jdbc/src/test/kotlin/integration/jdbc/TemplateTest.kt
The English version of the documentation is currently under construction and will be available in a month or two. Questions are always welcome.😃
👍 1