Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

What's the recommend way to use transactions? #541

Open

Description

@ifyouseewendy

👋 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!

Activity

  1. marfoldi commented on Apr 30, 2021

    @marfoldi

    👋

    class ArticleRepository < Hanami::Repository
      def method
        transaction do
          # ...
        end
      end
    end
  2. monicao commented on Dec 30, 2021

    @monicao

    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.

  3. marfoldi commented on Jan 2, 2022

    @marfoldi

    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions