Class: Sequent::Core::Transactions::ReadOnlyActiveRecordTransactionProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/sequent/core/transactions/read_only_active_record_transaction_provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(transaction_provider) ⇒ ReadOnlyActiveRecordTransactionProvider

Returns a new instance of ReadOnlyActiveRecordTransactionProvider.



7
8
9
# File 'lib/sequent/core/transactions/read_only_active_record_transaction_provider.rb', line 7

def initialize(transaction_provider)
  @transaction_provider = transaction_provider
end

Instance Method Details

#transactional(&block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/sequent/core/transactions/read_only_active_record_transaction_provider.rb', line 11

def transactional(&block)
  register_call
  @transaction_provider.transactional do
    Sequent::ApplicationRecord.connection.execute('SET TRANSACTION READ ONLY')
    block.call
  rescue ActiveRecord::StatementInvalid
    @skip_set_transaction = true
    raise
  ensure
    deregister_call
    reset_stack_size if stack_size == 0
  end
end