module Olaf::QueryDefinition::ClassMethods
Public Instance Methods
argument(name, options = {})
click to toggle source
Define an argument for the query matching a placeholder in the template. The Sequel gem, will fill the placeholders in the SQL query escaping the value passed as an argument. Sometimes, we need to pass an argument as literal to avoid the single quotes added by Sequel (i.e. sending a table_name)
options - Hash config for each argument
:as - Argument Type * :literal - Forces a string substitution with the literal value
Example:
class OneQuery include Snowflake::QueryDefinition template 'reports/one.sql' argument :dealersip_id argument :table_name, as: :literal end
# File lib/olaf/query_definition/class_methods.rb, line 38 def argument(name, options = {}) return if arguments.key?(name) arguments[name] = { literal: options[:as] == :literal } name end
arguments()
click to toggle source
Returns ALL the arguments defined for the query, including options.
@return Hash
# File lib/olaf/query_definition/class_methods.rb, line 13 def arguments @arguments ||= {} end
prepare(**vars)
click to toggle source
Creates a new instance of the Query defined and validates the parameters passed, leaving the instance in a ready-to-execute state.
@return Snowflake::QueryDefinition instance
# File lib/olaf/query_definition/class_methods.rb, line 7 def prepare(**vars) new(**vars).prepare end
row_object(object_class = nil)
click to toggle source
Define the object representing each row of the result. When not specified, each row will be a hash by default.
Example:
class OneQuery include Snowflake::QueryDefinition row_object MyOwnObject end
# File lib/olaf/query_definition/class_methods.rb, line 73 def row_object(object_class = nil) @row_object ||= object_class end
template(file_name = nil)
click to toggle source
Define the file path to the SQL template for this query.
Example:
class OneQuery include Snowflake::QueryDefinition template 'reports/one.sql' end
# File lib/olaf/query_definition/class_methods.rb, line 57 def template(file_name = nil) @template ||= file_name end