class SnowflakeDB::Connection
Constants
- MAX_FILE_SIZE
- PG_INCLUDE_KEYS
Attributes
config[R]
max_file_size[R]
unload_target[R]
Public Class Methods
new(config)
click to toggle source
# 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
Public Instance Methods
connection()
click to toggle source
# File lib/snowflake_db/connection.rb, line 28 def connection @connection ||= connect! end
fetch_all_hash(query)
click to toggle source
# 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() { || ... }
click to toggle source
# 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
Private Instance Methods
connect!()
click to toggle source
# File lib/snowflake_db/connection.rb, line 51 def connect! Sequel.odbc(config['dsn'], user: config['username'], password: config['password']).tap do |conn| conn.run("ALTER SESSION SET STATEMENT_TIMEOUT_IN_SECONDS = #{@statement_timeout}/1000") if @statement_timeout end end
connection_expired_error?(exception)
click to toggle source
# File lib/snowflake_db/connection.rb, line 45 def connection_expired_error?(exception) # Whether the given exception is due connection expired error. e.g. # ODBC::Error: 08001 (390114) Authentication token has expired. The user must authenticate again. exception.message =~ /\(39011[0-5]\)/ end