Kotlin Context Receivers for Database Transactions

Описание к видео Kotlin Context Receivers for Database Transactions

In our last episode (   • Using PostgreSQL as an Append-only Da...  ) we introduced a repository to store our stock information, implemented in-memory, in a file, and with Postgres via the Exposed library. This left us with the issue of what to do about database transactions, which we would like to be set up by the caller of methods on our repository.

In this episode we first refactor our tests so that they can start the correct type of transaction for the different implementations, and then refactor the repository methods to take that transaction as a parameter. Once this is working, we move the parameter to a receiver, so that our methods have both repository and transaction receivers, before finally introducing the experimental context receivers (https://github.com/Kotlin/KEEP/blob/m...) that were introduced in Kotlin 1.6.20 and have still to be finalised.

By the end I think that the experiment should be judged a success - context receivers seem to work very well in this use-case - so we're going to risk adopting the technology while it is still experimental.

This is part 63 of an exploration of where a Test Driven Development implementation of the Gilded Rose stock control system might take us in Kotlin. You can see the whole series as a playlist
   • All Gilded Rose Episodes  
and the code on GitHub
https://github.com/dmcg/gilded-rose-tdd

If you like this, you’ll probably like my book Java to Kotlin, A Refactoring Guidebook
(http://java-to-kotlin.dev). It's about far more than just the syntax differences between the languages - it shows how to upgrade your thinking to a more functional style.

I have some free time between producing videos and working for team Gilded Rose. If you like these videos I'd like to work with you - please get in touch - [email protected]

Комментарии

Информация по комментариям в разработке