module Olaf

Public Class Methods

configure(olaf_driver: Olaf::Snowflake, **args) click to toggle source

Configures Olaf module to execute queries in Snowflake or in a local object to prevent external calls. Arguments passed will be forwarded directly to the `olaf_driver` class specified.

By default, it will set a connection with Snowflake

# File lib/olaf.rb, line 15
def self.configure(olaf_driver: Olaf::Snowflake, **args)
  @instance = olaf_driver.new(**args)
end
execute(olaf_query) click to toggle source

Executes a query defined by Olaf::QueryDefinition with the driver configured previously.

@return Enumerable of results.
  (i.e. Array of Hashes or `row_objects` when specified)

@raises Olaf::QueryExecutionError
# File lib/olaf.rb, line 26
def self.execute(olaf_query)
  row_object = olaf_query.class.row_object
  row_transformer = row_object ? ->(r) { row_object.new(**r) } : Proc.new(&:itself)

  instance
    .fetch(olaf_query)
    .map!(&row_transformer)
rescue Sequel::DatabaseError => error
  raise QueryExecutionError.new(error.message, olaf_query)
end
instance() click to toggle source

Returns an instance to execute queries when its configured.

@return Olaf driver instance
  * Olaf::Fake      - Ideal for testing
  * Olaf::Snowflake - Sequel.odbc driver to run queries in Snowflake
# File lib/olaf.rb, line 43
def self.instance
  @instance || raise('You need to configure Olaf before using it!')
end