Class: Babik::Selection::Operation::Week

Inherits:
DateOperation show all
Defined in:
lib/babik/queryset/lib/selection/operation/date.rb

Overview

ISO Week of year (1-52/53) from date operation

Constant Summary

Constants inherited from DateOperation

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

Methods inherited from DateOperation

#initialize

Methods included from ValidDBMS

#assert_dbms

Methods inherited from Base

#_init_sql_operation, date_special_cases, #db_engine, escape, factory, #initialize, initialize_operation, initialize_operators, operator?, special_cases, #to_s

Constructor Details

This class inherits a constructor from Babik::Selection::Operation::DateOperation

Instance Method Details

#sql_functionObject

Raises:

  • (NotImplementedError)


120
121
122
123
124
125
126
# File 'lib/babik/queryset/lib/selection/operation/date.rb', line 120

def sql_function
  dbms_adapter = db_engine
  return 'WEEK(#field, 3)' if dbms_adapter == 'mysql2'
  return 'EXTRACT(WEEK FROM #field)' if dbms_adapter == 'postgresql'
  return '(strftime(\'%j\', date(#field, \'-3 days\', \'weekday 4\')) - 1) / 7 + 1' if dbms_adapter == 'sqlite3'
  raise NotImplementedError, "#{self.class} lookup not implemented for #{dbms_adapter}"
end