What's the recommend way to use transactions?
👋 I've searched around the code base. It seems the transaction support is removed from hanami model. Hanami::Model.container.gateways[:default].connection seems to be a Sequel::Mysql2::Database which I could call transaction on it. May I ask if there is a recommended way to do it in hanami model? Thanks!
👋
class ArticleRepository < Hanami::Repository
def method
transaction do
# ...
end
end
end
Thanks @marfoldi . How about if you need to write records to two or more separate tables in a transaction?
For example, you have some User data and some UserAddress data that needs to be persisted in an atomic way.
For example, you have some User data and some UserAddress data that needs to be persisted in an atomic way.
Maybe something like:
def update_user(user_repository: UserRepository.new, user_address_repository: UserAddressRepository.new)
user_repository.transaction do
user_repository.update(...)
user_address_repository.update(...)
end
end