Class: Purview::RawConnections::Base
Class Method Summary
collapse
Instance Method Summary
collapse
#logger, #logger_opts, #logger_type, #with_context_logging
#blank?, #coalesced, #filter_blank_values, #filter_nil_values, #present?, #zero?
Constructor Details
#initialize(opts) ⇒ Base
Returns a new instance of Base.
14
15
16
17
|
# File 'lib/purview/raw_connections/base.rb', line 14
def initialize(opts)
@opts = opts
@raw_connection = new_connection
end
|
Class Method Details
.connect(opts) ⇒ Object
4
5
6
|
# File 'lib/purview/raw_connections/base.rb', line 4
def self.connect(opts)
new(opts)
end
|
.with_new_connection(opts) ⇒ Object
8
9
10
11
12
|
# File 'lib/purview/raw_connections/base.rb', line 8
def self.with_new_connection(opts)
yield connection = connect(opts)
ensure
connection.disconnect if connection
end
|
Instance Method Details
#disconnect ⇒ Object
19
20
21
22
23
|
# File 'lib/purview/raw_connections/base.rb', line 19
def disconnect
raw_connection.close
@raw_connection = nil
self
end
|
#execute(sql, opts = {}) ⇒ Object
25
26
27
28
29
|
# File 'lib/purview/raw_connections/base.rb', line 25
def execute(sql, opts={})
logger.debug("Executing: #{sql}")
result = execute_sql(sql, opts)
structify_result(result)
end
|
#with_transaction ⇒ Object
31
32
33
34
35
36
37
|
# File 'lib/purview/raw_connections/base.rb', line 31
def with_transaction
execute_sql(BEGIN_TRANSACTION)
yield.tap { |result| execute_sql(COMMIT_TRANSACTION) }
rescue
execute_sql(ROLLBACK_TRANSACTION)
raise
end
|