Module: DWH::Functions
- Includes:
- Arrays, Dates, ExtractDatePart, Nulls
- Included in:
- Adapters::Adapter
- Defined in:
- lib/dwh/functions.rb,
lib/dwh/functions/dates.rb,
lib/dwh/functions/nulls.rb,
lib/dwh/functions/arrays.rb,
lib/dwh/functions/extract_date_part.rb
Overview
The Functions module adds a translation layer between this library and native database functions. It relies on the adapters settings file to map standard function to its native counterpart.
Defined Under Namespace
Modules: Arrays, Dates, ExtractDatePart, Nulls
Constant Summary
Constants included from Dates
Dates::DATE_CLASSES, Dates::TIMESTAMPABLE_UNITS
Instance Method Summary collapse
-
#cast(exp, type) ⇒ Object
Casts an expresion/literal to the target datatype.
-
#cross_join(relation) ⇒ Object
Applies adapter specific cross join expression This takes the target table.
-
#gsk(key) ⇒ String
Shortcut to get settings value by key.
- #lower_case(exp) ⇒ Object
-
#quote(exp) ⇒ Object
Applies adapter specific quotes around the given expression.
-
#string_lit(exp) ⇒ Object
Applies adapter specific string literal translation around the given expression.
- #trim(exp) ⇒ Object
- #upper_case(exp) ⇒ Object
Methods included from Arrays
#array_exclude_list, #array_in_list, #array_unnest_join
Methods included from Nulls
#if_null, #null_if, #null_if_zero
Methods included from ExtractDatePart
#extract_day_name, #extract_day_of_month, #extract_day_of_week, #extract_day_of_year, #extract_hour, #extract_minute, #extract_month, #extract_month_name, #extract_quarter, #extract_week_of_year, #extract_year, #extract_year_month
Methods included from Dates
#adjust_week_start_day, #adjust_week_start_day?, #current_date, #current_time, #current_timestamp, #date_add, #date_data_type, #date_diff, #date_format, #date_format_sql, #date_int?, #date_lit, #date_literal, #date_time_format, #date_time_literal, #date_time_tz_format, #default_week_start_day, #timestamp_lit, #timestamp_literal, #truncate_date, #week_start_day, #week_starts_on_sunday?
Instance Method Details
#cast(exp, type) ⇒ Object
Casts an expresion/literal to the target datatype. Datatype should be valid for the target db.
31 32 33 34 |
# File 'lib/dwh/functions.rb', line 31 def cast(exp, type) gsk(:cast).gsub(/@exp/i, exp) .gsub(/@type/i, type) end |
#cross_join(relation) ⇒ Object
Applies adapter specific cross join expression This takes the target table. Ie if you are joining table a with table b.. You will pass in the table b name expression here.
74 75 76 |
# File 'lib/dwh/functions.rb', line 74 def cross_join(relation) gsk(:cross_join).sub(/@relation/i, relation) end |
#gsk(key) ⇒ String
Shortcut to get settings value by key.
82 83 84 |
# File 'lib/dwh/functions.rb', line 82 def gsk(key) settings[key.to_sym] end |
#lower_case(exp) ⇒ Object
40 41 42 |
# File 'lib/dwh/functions.rb', line 40 def lower_case(exp) gsk(:lower_case).gsub(/@exp/i, exp) end |
#quote(exp) ⇒ Object
Applies adapter specific quotes around the given expression. The expression is usually a column name, alias, or table alias.
53 54 55 |
# File 'lib/dwh/functions.rb', line 53 def quote(exp) gsk(:quote).sub(/@exp/i, exp) end |
#string_lit(exp) ⇒ Object
Applies adapter specific string literal translation around the given expression. The expression is usually a string value.
61 62 63 |
# File 'lib/dwh/functions.rb', line 61 def string_lit(exp) gsk(:string_literal).sub(/@exp/i, exp.gsub("'", "''")) end |
#trim(exp) ⇒ Object
36 37 38 |
# File 'lib/dwh/functions.rb', line 36 def trim(exp) gsk(:trim).gsub(/@exp/i, exp) end |
#upper_case(exp) ⇒ Object
44 45 46 |
# File 'lib/dwh/functions.rb', line 44 def upper_case(exp) gsk(:upper_case).gsub(/@exp/i, exp) end |