Class: Adhoq::Executor::ConnectionWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/adhoq/executor/connection_wrapper.rb

Instance Method Summary collapse

Constructor Details

#initializeConnectionWrapper

Returns a new instance of ConnectionWrapper.



4
5
# File 'lib/adhoq/executor/connection_wrapper.rb', line 4

def initialize
end

Instance Method Details

#explain(query) ⇒ Object



13
14
15
16
17
# File 'lib/adhoq/executor/connection_wrapper.rb', line 13

def explain(query)
  with_sandbox do |connection|
    connection.explain(query)
  end
end

#select(query) ⇒ Object



7
8
9
10
11
# File 'lib/adhoq/executor/connection_wrapper.rb', line 7

def select(query)
  with_sandbox do |connection|
    connection.exec_query(query)
  end
end

#with_connection {|connection| ... } ⇒ Object

Yields:

  • (connection)


19
20
21
22
# File 'lib/adhoq/executor/connection_wrapper.rb', line 19

def with_connection
  connection = Adhoq.config.callablize(:database_connection).call
  yield(connection)
end

#with_sandboxObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/adhoq/executor/connection_wrapper.rb', line 24

def with_sandbox
  result = nil
  with_connection do |connection|
    connection.transaction do
      result = yield(connection)
      raise ActiveRecord::Rollback
    end
  end
  result
end