
Lightweight micro-ORM enabling explicit SQL-driven data access with mandatory transaction scopes, convenient DSLs, parameter mappers, and an optional compiler plugin to auto-generate row mappers.
Mikrom is inspired by Dapper, a popular micro ORM for .NET.
Note: This library is in an early phase. The API is highly likely to have breaking changes sometimes, but I would value your feedback on the library design.
| Mikrom version | Kotlin version required |
|---|---|
| 0.7.x+ | 2.4.21 |
| 0.6.x | 2.3.20 |
| 0.5.x | 2.3.10 |
Add the Gradle plugin and dependency:
plugins {
id("io.github.kantis.mikrom") version "0.7.0"
}
dependencies {
implementation("io.github.kantis:mikrom-jdbc:0.7.0")
}Create a JDBC connection and construct a Mikrom instance:
fun main() {
val dbConnection = DriverManager.getConnection("jdbc:your_database_url")
val dataSource = JdbcDataSource(dbConnection)
val mikrom = Mikrom {}
dataSource.transaction {
// Using named parameters with a generated ParameterMapper
mikrom.execute(
"""
INSERT INTO books(author, title, number_of_pages)
VALUES (:author, :title, :numberOfPages)
""",
CreateBookCommand("JRR Tolkien", BookTitle("The Hobbit"), 310),
CreateBookCommand("George Orwell", BookTitle("1984"), 328),
)
// or, using positional parameters
mikrom.execute(
"INSERT INTO books(author, title, number_of_pages) VALUES (?, ?, ?)",
listOf("JRR Tolkien", "The Hobbit", 310),
listOf("George Orwell", "1984", 328),
)
mikrom.queryFor<Book>(
"SELECT * FROM books WHERE number_of_pages > ?", 311
) // Book("George Orwell", BookTitle("1984"), 328)
}
}
@MikromParameter
data class CreateBookCommand(val author: String, val title: BookTitle, val numberOfPages: Int)
@JvmInline
value class BookTitle(val title: String)
@MikromResult
data class Book(val author: String, val title: BookTitle, val numberOfPages: Int)The same API is available as suspending functions on top of an R2DBC ConnectionPool:
dependencies {
implementation("io.github.kantis:mikrom-r2dbc:0.7.0")
}import io.github.kantis.mikrom.suspend.execute
import io.github.kantis.mikrom.suspend.queryFor
import io.github.kantis.mikrom.suspend.queryForFlow
suspend fun main() {
val dataSource = PooledR2dbcDataSource(connectionPool) // an io.r2dbc.pool.ConnectionPool
val mikrom = Mikrom {}
dataSource.suspendingTransaction {
mikrom.execute(
"INSERT INTO books(author, title, number_of_pages) VALUES (:author, :title, :numberOfPages)",
CreateBookCommand("JRR Tolkien", BookTitle("The Hobbit"), 310),
)
// Loads the full result, like the blocking API
mikrom.queryFor<Book>("SELECT * FROM books WHERE number_of_pages > :minPages", mapOf("minPages" to 300))
// Or stream it; the Flow must be collected before the transaction block returns
mikrom.queryForFlow<Book>("SELECT * FROM books").collect { println(it) }
}
}See the getting started guide for details on placeholders, null handling and streaming.
Copyright (C) 2025 Emil Kantis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Mikrom is inspired by Dapper, a popular micro ORM for .NET.
Note: This library is in an early phase. The API is highly likely to have breaking changes sometimes, but I would value your feedback on the library design.
| Mikrom version | Kotlin version required |
|---|---|
| 0.7.x+ | 2.4.21 |
| 0.6.x | 2.3.20 |
| 0.5.x | 2.3.10 |
Add the Gradle plugin and dependency:
plugins {
id("io.github.kantis.mikrom") version "0.7.0"
}
dependencies {
implementation("io.github.kantis:mikrom-jdbc:0.7.0")
}Create a JDBC connection and construct a Mikrom instance:
fun main() {
val dbConnection = DriverManager.getConnection("jdbc:your_database_url")
val dataSource = JdbcDataSource(dbConnection)
val mikrom = Mikrom {}
dataSource.transaction {
// Using named parameters with a generated ParameterMapper
mikrom.execute(
"""
INSERT INTO books(author, title, number_of_pages)
VALUES (:author, :title, :numberOfPages)
""",
CreateBookCommand("JRR Tolkien", BookTitle("The Hobbit"), 310),
CreateBookCommand("George Orwell", BookTitle("1984"), 328),
)
// or, using positional parameters
mikrom.execute(
"INSERT INTO books(author, title, number_of_pages) VALUES (?, ?, ?)",
listOf("JRR Tolkien", "The Hobbit", 310),
listOf("George Orwell", "1984", 328),
)
mikrom.queryFor<Book>(
"SELECT * FROM books WHERE number_of_pages > ?", 311
) // Book("George Orwell", BookTitle("1984"), 328)
}
}
@MikromParameter
data class CreateBookCommand(val author: String, val title: BookTitle, val numberOfPages: Int)
@JvmInline
value class BookTitle(val title: String)
@MikromResult
data class Book(val author: String, val title: BookTitle, val numberOfPages: Int)The same API is available as suspending functions on top of an R2DBC ConnectionPool:
dependencies {
implementation("io.github.kantis:mikrom-r2dbc:0.7.0")
}import io.github.kantis.mikrom.suspend.execute
import io.github.kantis.mikrom.suspend.queryFor
import io.github.kantis.mikrom.suspend.queryForFlow
suspend fun main() {
val dataSource = PooledR2dbcDataSource(connectionPool) // an io.r2dbc.pool.ConnectionPool
val mikrom = Mikrom {}
dataSource.suspendingTransaction {
mikrom.execute(
"INSERT INTO books(author, title, number_of_pages) VALUES (:author, :title, :numberOfPages)",
CreateBookCommand("JRR Tolkien", BookTitle("The Hobbit"), 310),
)
// Loads the full result, like the blocking API
mikrom.queryFor<Book>("SELECT * FROM books WHERE number_of_pages > :minPages", mapOf("minPages" to 300))
// Or stream it; the Flow must be collected before the transaction block returns
mikrom.queryForFlow<Book>("SELECT * FROM books").collect { println(it) }
}
}See the getting started guide for details on placeholders, null handling and streaming.
Copyright (C) 2025 Emil Kantis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.