Class: Adhoq::Executor::ConnectionWrapper
- Inherits:
-
Object
- Object
- Adhoq::Executor::ConnectionWrapper
- Defined in:
- lib/adhoq/executor/connection_wrapper.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
- #explain(query) ⇒ Object
-
#initialize ⇒ ConnectionWrapper
constructor
A new instance of ConnectionWrapper.
- #select(query) ⇒ Object
- #with_sandbox ⇒ Object
Constructor Details
#initialize ⇒ ConnectionWrapper
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
#connection ⇒ Object (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_sandbox ⇒ Object
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 |