Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension for Sequel transactions #21

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Sep 13, 2024

  1. Add extension for Sequel transactions

    We add a `Dry::Operation::Extensions::Sequel` module that, when included, gives access to a `#transaction` method. This method wraps the yielded steps in a [Sequel](https://sequel.jeremyevans.net/) transaction, rolling back in case one of them returns a failure.
    
    The extension expects the including class to define a `#db` method giving access to the Sequel database definition:
    
    ```ruby
    class MyOperation < Dry::Operation
      include Dry::Operation::Extensions::Sequel
    
      attr_reader :db
    
      def initialize(db:)
        @db = db
      end
    
      def call(input)
        attrs = step validate(input)
        user = transaction do
          new_user = step persist(attrs)
          step assign_initial_role(new_user)
          new_user
        end
        step notify(user)
        user
      end
    
      # ...
    end
    ```
    
    Default options for the `#transaction` options (which delegates to Sequel [transaction method](https://sequel.jeremyevans.net/rdoc/files/doc/transactions_rdoc.html)) can be given both at include time with `include Dry::Operation::Extensions::Sequel[isolation: :serializable]`, and at runtime with `#transaction(isolation: :serializable)`.
    waiting-for-dev committed Sep 13, 2024
    Configuration menu
    Copy the full SHA
    c74658a View commit details
    Browse the repository at this point in the history