sqltgen generates JDBC-based Kotlin code using the standard java.sql package.
Generated code uses Kotlin idioms: data classes, nullable types, and Kotlin objects.
src/main/kotlin/com/example/db/
Author.kt — data class for the author table
Book.kt — data class for the book table
Queries.kt — Kotlin object with query functions
Querier.kt — DataSource-backed wrapper object
// Author.kt
package com.example.db
data class Author(
val id: Long,
val name: String,
val bio: String?, // nullable → T?
val birthYear: Int? // nullable → T?
)
Non-null columns use non-nullable Kotlin types (Long, Int, Boolean, etc.).
Nullable columns use Kotlin nullable types (Long?, Int?, String?, etc.).
import java.sql.DriverManager
import com.example.db.Queries
val conn = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/mydb", "user", "pass")
val author = Queries.getAuthor(conn, 1L)
val all = Queries.listAuthors(conn)
object Queries {
data class ListBooksWithAuthorRow(
val id: Long,
val title: String,
val genre: String,
val price: java.math.BigDecimal,
val authorName: String,
val authorBio: String?
)
fun listBooksWithAuthor(conn: Connection): List<ListBooksWithAuthorRow> { … }
}