Class: Babik::Selection::Operation::Day
- Inherits:
-
DateOperation
- Object
- Base
- DateOperation
- Babik::Selection::Operation::Day
- Defined in:
- lib/babik/queryset/lib/selection/operation/date.rb
Overview
Day of month date operation
Constant Summary
Constants inherited from DateOperation
Babik::Selection::Operation::DateOperation::HAS_OPERATOR
Constants included from ValidDBMS
ValidDBMS::SUPPORTED_DB_ADAPTERS
Instance Attribute Summary
Attributes inherited from Base
#field, #sql_operation, #sql_operation_template, #value
Instance Method Summary collapse
-
#initialize(field, operator, value) ⇒ Day
constructor
A new instance of Day.
- #sql_function ⇒ Object
Methods included from ValidDBMS
Methods inherited from Base
#_init_sql_operation, date_special_cases, #db_engine, escape, factory, initialize_operation, initialize_operators, operator?, special_cases, #to_s
Constructor Details
#initialize(field, operator, value) ⇒ Day
Returns a new instance of Day.
85 86 87 88 |
# File 'lib/babik/queryset/lib/selection/operation/date.rb', line 85 def initialize(field, operator, value) value = format('%02d', value) if db_engine == 'sqlite3' super(field, operator, value) end |
Instance Method Details
#sql_function ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/babik/queryset/lib/selection/operation/date.rb', line 90 def sql_function dbms_adapter = db_engine return 'DAYOFMONTH(#field)' if dbms_adapter == 'mysql2' return 'EXTRACT(DAY FROM #field)' if dbms_adapter == 'postgresql' return 'strftime(\'%d\', #field)' if dbms_adapter == 'sqlite3' raise NotImplementedError, "#{self.class} lookup not implemented for #{dbms_adapter}" end |