Class: SnowflakeDB::Connection
- Inherits:
-
Object
- Object
- SnowflakeDB::Connection
- Defined in:
- lib/snowflake_db/connection.rb
Constant Summary collapse
- PG_INCLUDE_KEYS =
%w(host dbname port user password)- MAX_FILE_SIZE =
5.gigabytes.freeze
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#max_file_size ⇒ Object
readonly
Returns the value of attribute max_file_size.
-
#unload_target ⇒ Object
readonly
Returns the value of attribute unload_target.
Instance Method Summary collapse
- #connection ⇒ Object
- #fetch_all_hash(query) ⇒ Object
-
#initialize(config) ⇒ Connection
constructor
A new instance of Connection.
- #reconnect_on_failure(&block) ⇒ Object
Constructor Details
#initialize(config) ⇒ Connection
Returns a new instance of Connection.
10 11 12 13 14 15 |
# File 'lib/snowflake_db/connection.rb', line 10 def initialize(config) @config = config @statement_timeout = config['statement_timeout'] @unload_target = config['unload_target'] @max_file_size = config['max_file_size'] || MAX_FILE_SIZE end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/snowflake_db/connection.rb', line 5 def config @config end |
#max_file_size ⇒ Object (readonly)
Returns the value of attribute max_file_size.
5 6 7 |
# File 'lib/snowflake_db/connection.rb', line 5 def max_file_size @max_file_size end |
#unload_target ⇒ Object (readonly)
Returns the value of attribute unload_target.
5 6 7 |
# File 'lib/snowflake_db/connection.rb', line 5 def unload_target @unload_target end |
Instance Method Details
#connection ⇒ Object
28 29 30 |
# File 'lib/snowflake_db/connection.rb', line 28 def connection @connection ||= connect! end |
#fetch_all_hash(query) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/snowflake_db/connection.rb', line 32 def fetch_all_hash(query) # execute a query and return the entire result as an array of hashes keyed by column names result = [] reconnect_on_failure do connection.fetch(query) do |row| result << row.stringify_keys end end result end |
#reconnect_on_failure(&block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/snowflake_db/connection.rb', line 17 def reconnect_on_failure(&block) begin return yield rescue Sequel::DatabaseError => e raise unless connection_expired_error?(e) @connection.disconnect if @connection.connected? @connection = nil return yield # retry once end end |