Sha256: be0a3731164a972b5801e0b5b1813e2656873ac95ae3f53d144f57cc9b6902e9

Contents?: true

Size: 621 Bytes

Versions: 3

Compression:

Stored size: 621 Bytes

Contents

require 'active_record'

module Glueby
  module AR
    autoload :SystemInformation, 'glueby/active_record/system_information'

    def transaction(isolation: nil)
      options = { joinable: false, requires_new: true }

      adapter_type = ActiveRecord::Base.connection.adapter_name.downcase

      # SQLite3 does not support transaction isolation level READ COMMITTED.
      if isolation == :read_committed && adapter_type == 'mysql2'
        options[:isolation] = :read_committed
      end

      ActiveRecord::Base.transaction(**options) do
        yield
      end
    end

    module_function :transaction
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
glueby-1.4.0 lib/glueby/active_record.rb
glueby-1.3.0 lib/glueby/active_record.rb
glueby-1.2.3 lib/glueby/active_record.rb