Class: Groupdate::Adapters::SQLiteAdapter
- Inherits:
-
BaseAdapter
- Object
- BaseAdapter
- Groupdate::Adapters::SQLiteAdapter
- Defined in:
- lib/groupdate/adapters/sqlite_adapter.rb
Instance Attribute Summary
Attributes inherited from BaseAdapter
#column, #day_start, #n_seconds, #period, #week_start
Instance Method Summary collapse
Methods inherited from BaseAdapter
Constructor Details
This class inherits a constructor from Groupdate::Adapters::BaseAdapter
Instance Method Details
#group_clause ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/groupdate/adapters/sqlite_adapter.rb', line 4 def group_clause query = if period == :week ["strftime('%Y-%m-%d', #{column}, '-6 days', ?)", "weekday #{(week_start + 1) % 7}"] elsif period == :custom ["datetime((strftime('%s', #{column}) / ?) * ?, 'unixepoch')", n_seconds, n_seconds] else format = case period when :minute_of_hour "%M" when :hour_of_day "%H" when :day_of_week "%w" when :day_of_month "%d" when :day_of_year "%j" when :month_of_year "%m" when :second "%Y-%m-%d %H:%M:%S UTC" when :minute "%Y-%m-%d %H:%M:00 UTC" when :hour "%Y-%m-%d %H:00:00 UTC" when :day "%Y-%m-%d" when :month "%Y-%m-01" when :quarter nil else # year "%Y-01-01" end ["strftime(?, #{column})", format] end if period != :custom && (@time_zone != SeriesBuilder.utc || day_start != 0 || period == :quarter) setup_function week_start = period == :week ? Groupdate::Magic::DAYS[self.week_start].to_s : nil query = ["groupdate_internal(?, #{column}, ?, ?, ?)", period, @time_zone.tzinfo.name, day_start, week_start] end @relation.send(:sanitize_sql_array, query) end |