Class: RedshiftPG::Connection
- Inherits:
-
Object
- Object
- RedshiftPG::Connection
- Defined in:
- lib/redshift_pg/connection.rb
Constant Summary collapse
- SQL_TO_PG_KEY_MAP =
{ 'username' => 'user', 'database' => 'dbname' }
- PG_INCLUDE_KEYS =
%w(host dbname port user password)
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #fetch_all_hash(query) ⇒ Object
-
#initialize(config) ⇒ Connection
constructor
A new instance of Connection.
- #pg_connection ⇒ Object
- #reconnect_on_failure(&block) ⇒ Object
Constructor Details
#initialize(config) ⇒ Connection
Returns a new instance of Connection.
13 14 15 16 |
# File 'lib/redshift_pg/connection.rb', line 13 def initialize(config) @config = config @statement_timeout = config['statement_timeout'] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
4 5 6 |
# File 'lib/redshift_pg/connection.rb', line 4 def config @config end |
Instance Method Details
#fetch_all_hash(query) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/redshift_pg/connection.rb', line 31 def fetch_all_hash(query) # execute a query and return the entire result as an array of hashes keyed by column names reconnect_on_failure do pg_connection.exec(query).to_a end end |
#pg_connection ⇒ Object
27 28 29 |
# File 'lib/redshift_pg/connection.rb', line 27 def pg_connection @pg_connection ||= connect! end |
#reconnect_on_failure(&block) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/redshift_pg/connection.rb', line 18 def reconnect_on_failure(&block) begin return yield rescue PG::UnableToSend, PG::ConnectionBad pg_connection.reset return yield # retry once end end |