Class: ForestAdminDatasourceSnowflake::Datasource
- Inherits:
-
ForestAdminDatasourceToolkit::Datasource
- Object
- ForestAdminDatasourceToolkit::Datasource
- ForestAdminDatasourceSnowflake::Datasource
- Defined in:
- lib/forest_admin_datasource_snowflake/datasource.rb
Constant Summary collapse
- DEFAULT_POOL_SIZE =
5- DEFAULT_POOL_TIMEOUT =
5- CONNECTION_LOST_PATTERNS =
[ /Communication link failure/i, /Connection.*lost/i, /Connection is closed/i, /Session.*expired/i, /Session.*timed out/i, /Broken pipe/i, /Not connected/i, /timeout expired/i, /Authentication token has expired/i, /token.*expired/i ].freeze
- SYSTEM_SCHEMAS =
%w[INFORMATION_SCHEMA].freeze
Instance Attribute Summary collapse
-
#pool ⇒ Object
readonly
Returns the value of attribute pool.
Instance Method Summary collapse
-
#initialize(conn_str:, pool_size: DEFAULT_POOL_SIZE, pool_timeout: DEFAULT_POOL_TIMEOUT, statement_timeout: nil, primary_keys: nil) ⇒ Datasource
constructor
A new instance of Datasource.
- #primary_keys_for(table_name) ⇒ Object
- #primary_keys_override_for(table_name) ⇒ Object
- #shutdown! ⇒ Object
- #snowflake_columns_for(table_name) ⇒ Object
- #with_connection(&block) ⇒ Object
Constructor Details
#initialize(conn_str:, pool_size: DEFAULT_POOL_SIZE, pool_timeout: DEFAULT_POOL_TIMEOUT, statement_timeout: nil, primary_keys: nil) ⇒ Datasource
Returns a new instance of Datasource.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/forest_admin_datasource_snowflake/datasource.rb', line 26 def initialize(conn_str:, pool_size: DEFAULT_POOL_SIZE, pool_timeout: DEFAULT_POOL_TIMEOUT, statement_timeout: nil, primary_keys: nil) super() @schema_override = extract_schema_from_conn_str(conn_str) @statement_timeout = statement_timeout @primary_keys_override = (primary_keys || {}).transform_keys { |k| k.to_s.upcase } @pool = ConnectionPool.new(size: pool_size, timeout: pool_timeout) do open_connection(conn_str) end @schema_override ||= resolve_default_schema! generate_collections discover_relations end |
Instance Attribute Details
#pool ⇒ Object (readonly)
Returns the value of attribute pool.
24 25 26 |
# File 'lib/forest_admin_datasource_snowflake/datasource.rb', line 24 def pool @pool end |
Instance Method Details
#primary_keys_for(table_name) ⇒ Object
61 62 63 64 65 66 |
# File 'lib/forest_admin_datasource_snowflake/datasource.rb', line 61 def primary_keys_for(table_name) upper = table_name.to_s.upcase return Array(@primary_keys_override[upper]) if @primary_keys_override.key?(upper) (snowflake_primary_keys || {})[upper] || [] end |
#primary_keys_override_for(table_name) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/forest_admin_datasource_snowflake/datasource.rb', line 68 def primary_keys_override_for(table_name) upper = table_name.to_s.upcase return nil unless @primary_keys_override.key?(upper) Array(@primary_keys_override[upper]) end |
#shutdown! ⇒ Object
57 58 59 |
# File 'lib/forest_admin_datasource_snowflake/datasource.rb', line 57 def shutdown! @pool.shutdown { |conn| safe_disconnect(conn) } end |
#snowflake_columns_for(table_name) ⇒ Object
75 76 77 |
# File 'lib/forest_admin_datasource_snowflake/datasource.rb', line 75 def snowflake_columns_for(table_name) (snowflake_columns || {})[table_name.to_s.upcase] || [] end |
#with_connection(&block) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/forest_admin_datasource_snowflake/datasource.rb', line 43 def with_connection(&block) retried = false begin @pool.with(&block) rescue ::ODBC::Error => e if !retried && connection_lost?(e) retried = true reset_pool! retry end raise end end |