Jeff Hudson
09/05/2025, 2:27 PMNo transaction in context. error when I don't think it should be 🧵Jeff Hudson
09/05/2025, 2:27 PMfun main() {
runBlocking {
val database = createDatabase()
val ktorServer = createKtorServer(database)
ktorServer.start()
Thread.sleep(Long.MAX_VALUE)
}
}
private fun createDatabase() =
R2dbcDatabase.connect(
url = "r2dbc:<postgresql://localhost:5432/kairo_sample>",
user = "highbeam",
password = "highbeam",
)
private fun createKtorServer(database: R2dbcDatabase) =
embeddedServer(
factory = Netty,
environment = applicationEnvironment(),
configure = {
connector {
host = "0.0.0.0"
port = 8080
}
},
module = {
install(CallLogging)
routing {
get("/library-books") {
suspendTransaction(db = database) {
LibraryBookTable.selectAll().toList()
}
call.respond("It worked!")
}
}
},
)
and my table
object LibraryBookTable : Table("library.library_book") {
val id: Column<String> =
text("id")
override val primaryKey: PrimaryKey = PrimaryKey(id)
val createdAt: Column<Instant> =
timestamp("created_at")
.defaultExpression(CurrentTimestamp)
val version: Column<Long> =
long("version")
.default(0)
val updatedAt: Column<Instant> =
timestamp("updated_at")
.defaultExpression(CurrentTimestamp)
val title: Column<String?> =
text("title").nullable()
val authors: Column<List<String>> =
array<String>("authors")
val isbn: Column<String> =
text("isbn")
.uniqueIndex("uq__library_book__isbn")
}Jeff Hudson
09/05/2025, 2:28 PMcurl -v <http://localhost:8080/library-books> causes a 500 with No transaction in context.Jeff Hudson
09/05/2025, 2:32 PMAlexander af Trolle
09/06/2025, 11:34 AMplanerist
09/06/2025, 3:52 PMOleg Babichev
09/10/2025, 11:06 AMJeff Hudson
09/10/2025, 5:29 PMJeff Hudson
09/28/2025, 10:37 PMJeff Hudson
10/06/2025, 2:30 PM