Sha256: c098eb5c67f266f5f7d11a30f373c0428594dce0b99b5a8a7686277be43a82a9

Contents?: true

Size: 867 Bytes

Versions: 37

Compression:

Stored size: 867 Bytes

Contents

require 'rom/commands/result'

module ROM
  module SQL
    module Commands
      # Adds transaction interface to commands
      #
      # @api private
      module Transaction
        ROM::SQL::Rollback = Class.new(Sequel::Rollback)

        # Start a transaction
        #
        # @param [Hash] options The options hash supported by Sequel
        #
        # @return [ROM::Commands::Result::Success,ROM::Commands::Result::Failure]
        #
        # @api public
        def transaction(options = {}, &block)
          result = relation.dataset.db.transaction(options, &block)

          if result
            ROM::Commands::Result::Success.new(result)
          else
            ROM::Commands::Result::Failure.new(result)
          end
        rescue ROM::CommandError => e
          ROM::Commands::Result::Failure.new(e)
        end
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
rom-sql-1.3.5 lib/rom/sql/commands/transaction.rb
rom-sql-1.3.4 lib/rom/sql/commands/transaction.rb
rom-sql-2.0.0.beta1 lib/rom/sql/commands/transaction.rb
rom-sql-1.3.3 lib/rom/sql/commands/transaction.rb
rom-sql-1.3.2 lib/rom/sql/commands/transaction.rb
rom-sql-1.3.1 lib/rom/sql/commands/transaction.rb
rom-sql-1.3.0 lib/rom/sql/commands/transaction.rb
rom-sql-1.2.2 lib/rom/sql/commands/transaction.rb
rom-sql-1.2.1 lib/rom/sql/commands/transaction.rb
rom-sql-1.2.0 lib/rom/sql/commands/transaction.rb
rom-sql-1.1.2 lib/rom/sql/commands/transaction.rb
rom-sql-1.1.1 lib/rom/sql/commands/transaction.rb
rom-sql-1.1.0 lib/rom/sql/commands/transaction.rb
rom-sql-1.0.3 lib/rom/sql/commands/transaction.rb
rom-sql-1.0.2 lib/rom/sql/commands/transaction.rb
rom-sql-1.0.1 lib/rom/sql/commands/transaction.rb
rom-sql-1.0.0 lib/rom/sql/commands/transaction.rb
rom-sql-1.0.0.rc2 lib/rom/sql/commands/transaction.rb
rom-sql-1.0.0.rc1 lib/rom/sql/commands/transaction.rb
rom-sql-1.0.0.beta3 lib/rom/sql/commands/transaction.rb