
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.
Add the Gradle plugin and dependency:
plugins {
id("com.github.kantis.mikrom") version "0.5.0"
}
dependencies {
implementation("io.github.kantis.mikrom:mikrom-jdbc:0.5.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.transation {
// 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)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.
Add the Gradle plugin and dependency:
plugins {
id("com.github.kantis.mikrom") version "0.5.0"
}
dependencies {
implementation("io.github.kantis.mikrom:mikrom-jdbc:0.5.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.transation {
// 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)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.