I'm migrating some Scala code from Squeryl to Slick. Everything was going well until I bumped into the topic of transactions. Squeryl made dealing with transactions quite simple: you just need to wrap your code, be it DB-related or not, in a transaction
block and you're done.
From the examples I could gather online, it seems one is expected to re-structure the whole project to make it play nicely with its monadic approach and with for-comprehensions, which is something that I would really like to avoid.
Considering an arbitrary piece of code such as:
def f(): Unit = {
UserRepository.getUser()
... some imperative code
ServiceRepository.getServer()
...
ServerRepository.updateServer(...)
...
UserRepository.insertNewUser(...)
}
is there a way to easily wrap it in some sort of transactional block without having to change the internal logic of the method?