Class: Adhoq::Executor::ConnectionWrapper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnectionWrapper

Returns a new instance of ConnectionWrapper.



6
7
8
# File 'lib/adhoq/executor/connection_wrapper.rb', line 6

def initialize
  @connection = Adhoq.config.callablize(:database_connection).call
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



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

def connection
  @connection
end

Instance Method Details

#explain(query) ⇒ Object



16
17
18
19
20
# File 'lib/adhoq/executor/connection_wrapper.rb', line 16

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

#select(query) ⇒ Object



10
11
12
13
14
# File 'lib/adhoq/executor/connection_wrapper.rb', line 10

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

#with_sandboxObject



22
23
24
25
26
27
28
29
# File 'lib/adhoq/executor/connection_wrapper.rb', line 22

def with_sandbox
  result = nil
  connection.transaction do
    result = yield
    raise ActiveRecord::Rollback
  end
  result
end