The Sequel extension provides transaction support for operations when using the Sequel database toolkit. It will automatically roll back the transaction if any step returns a Failure.
Make sure you have sequel installed:
Require and include the extension in your operation class and provide access to the Sequel database object through a #db method:
include Dry::Operation::Extensions::Sequel
attr_reader :db
@db = db
super()
end
transaction do
user_id = step create_user(input)
step create_profile(user_id)
user_id
end
end
# ...
end
You can pass options to the transaction either when including the extension:
include Dry::Operation::Extensions::Sequel[isolation: :serializable]
Or at runtime:
transaction(isolation: :serializable) do
# ...
end
⚠️ Warning: The :savepoint option for nested transactions is not yet supported.