Class: Purview::Connections::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/purview/connections/base.rb

Direct Known Subclasses

MySQL, PostgreSQL

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Base

Returns a new instance of Base.



14
15
16
# File 'lib/purview/connections/base.rb', line 14

def initialize(opts)
  @raw_connection = raw_connection_type.connect(opts)
end

Class Method Details

.connect(opts) ⇒ Object



4
5
6
# File 'lib/purview/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/connections/base.rb', line 8

def self.with_new_connection(opts)
  yield connection = connect(opts)
ensure
  connection.disconnect if connection
end

Instance Method Details

#disconnectObject



18
19
20
21
22
# File 'lib/purview/connections/base.rb', line 18

def disconnect
  raw_connection.disconnect
  @raw_connection = nil
  self
end

#execute(sql) ⇒ Object



24
25
26
# File 'lib/purview/connections/base.rb', line 24

def execute(sql)
  raw_connection.execute(sql)
end

#with_transactionObject



28
29
30
# File 'lib/purview/connections/base.rb', line 28

def with_transaction
  raw_connection.with_transaction { yield }
end