Class: RedshiftSimpleMigrator::Connection
- Inherits:
-
Object
- Object
- RedshiftSimpleMigrator::Connection
- Defined in:
- lib/redshift_simple_migrator/connection.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
Instance Method Summary collapse
-
#initialize ⇒ Connection
constructor
A new instance of Connection.
- #with_transaction(&block) ⇒ Object
Constructor Details
#initialize ⇒ Connection
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
#connection ⇒ Object (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 |