Class: RedshiftSimpleMigrator::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/redshift_simple_migrator/connection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConnection

Returns a new instance of Connection.



20
21
22
23
# File 'lib/redshift_simple_migrator/connection.rb', line 20

def initialize
  @connection = PG.connect(RedshiftSimpleMigrator.config.database_config)
  @connection.type_map_for_results = PG::BasicTypeMapForResults.new(@connection)
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



7
8
9
# File 'lib/redshift_simple_migrator/connection.rb', line 7

def connection
  @connection
end

Instance Method Details

#with_transaction(&block) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/redshift_simple_migrator/connection.rb', line 25

def with_transaction(&block)
  connection.exec("BEGIN")
  block.call(self)
  connection.exec("COMMIT")
rescue => e
  connection.exec("ROLLBACK") if connection
  raise e
end