groupdate 6.5.0 → 6.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/CHANGELOG.md +4 -0
 - data/README.md +5 -3
 - data/lib/groupdate/adapters/base_adapter.rb +2 -1
 - data/lib/groupdate/adapters/postgresql_adapter.rb +1 -1
 - data/lib/groupdate/magic.rb +11 -9
 - data/lib/groupdate/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f55bd15dca1c101b40370cd1fb1f82eca0567fb73511849135a1989fa4a6a11a
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 7299ac70d10043b1f95de4885bb02683f55b33f1b075c7e5aced130ef8a6d979
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 9c1d74da58305bdf89f9c5196ef730712463e4c001ca4592a2f4d1b60d88deb5ca3ba6650f19d307a56e6ffc465f551b7d70ea14008c0445cad8d9f056e751f5
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 8ce0e0a7b317214b1eb31913083d9f8f6657b62255617752432c6ede1d3fb1e83cab133bc7cdd725c11522f4d2548ebef2df6bff271f06d02dfa6302e0954d77
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/README.md
    CHANGED
    
    | 
         @@ -11,7 +11,7 @@ The simplest way to group by: 
     | 
|
| 
       11 
11 
     | 
    
         | 
| 
       12 
12 
     | 
    
         
             
            :cake: Get the entire series - **the other best part**
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
     | 
    
         
            -
            Supports PostgreSQL, MySQL, and Redshift, plus arrays and hashes (and limited support for [SQLite](#for-sqlite))
         
     | 
| 
      
 14 
     | 
    
         
            +
            Supports PostgreSQL, MySQL, MariaDB, and Redshift, plus arrays and hashes (and limited support for [SQLite](#for-sqlite))
         
     | 
| 
       15 
15 
     | 
    
         | 
| 
       16 
16 
     | 
    
         
             
            :cupid: Goes hand in hand with [Chartkick](https://www.chartkick.com)
         
     | 
| 
       17 
17 
     | 
    
         | 
| 
         @@ -25,7 +25,7 @@ Add this line to your application’s Gemfile: 
     | 
|
| 
       25 
25 
     | 
    
         
             
            gem "groupdate"
         
     | 
| 
       26 
26 
     | 
    
         
             
            ```
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
            For MySQL and SQLite, also follow [these instructions](#additional-instructions).
         
     | 
| 
      
 28 
     | 
    
         
            +
            For MySQL, MariaDB, and SQLite, also follow [these instructions](#additional-instructions).
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
30 
     | 
    
         
             
            ## Getting Started
         
     | 
| 
       31 
31 
     | 
    
         | 
| 
         @@ -250,7 +250,9 @@ users.group_by_day { |u| u.created_at }.to_h { |k, v| [k, v.count] } 
     | 
|
| 
       250 
250 
     | 
    
         | 
| 
       251 
251 
     | 
    
         
             
            ## Additional Instructions
         
     | 
| 
       252 
252 
     | 
    
         | 
| 
       253 
     | 
    
         
            -
             
     | 
| 
      
 253 
     | 
    
         
            +
            <a name="for-mysql"></a>
         
     | 
| 
      
 254 
     | 
    
         
            +
             
     | 
| 
      
 255 
     | 
    
         
            +
            ### For MySQL and MariaDB
         
     | 
| 
       254 
256 
     | 
    
         | 
| 
       255 
257 
     | 
    
         
             
            [Time zone support](https://dev.mysql.com/doc/refman/8.0/en/time-zone-support.html) must be installed on the server.
         
     | 
| 
       256 
258 
     | 
    
         | 
| 
         @@ -3,7 +3,7 @@ module Groupdate 
     | 
|
| 
       3 
3 
     | 
    
         
             
                class BaseAdapter
         
     | 
| 
       4 
4 
     | 
    
         
             
                  attr_reader :period, :column, :day_start, :week_start, :n_seconds
         
     | 
| 
       5 
5 
     | 
    
         | 
| 
       6 
     | 
    
         
            -
                  def initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, n_seconds:)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  def initialize(relation, column:, period:, time_zone:, time_range:, week_start:, day_start:, n_seconds:, adapter_name: nil)
         
     | 
| 
       7 
7 
     | 
    
         
             
                    @relation = relation
         
     | 
| 
       8 
8 
     | 
    
         
             
                    @column = column
         
     | 
| 
       9 
9 
     | 
    
         
             
                    @period = period
         
     | 
| 
         @@ -12,6 +12,7 @@ module Groupdate 
     | 
|
| 
       12 
12 
     | 
    
         
             
                    @week_start = week_start
         
     | 
| 
       13 
13 
     | 
    
         
             
                    @day_start = day_start
         
     | 
| 
       14 
14 
     | 
    
         
             
                    @n_seconds = n_seconds
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @adapter_name = adapter_name
         
     | 
| 
       15 
16 
     | 
    
         | 
| 
       16 
17 
     | 
    
         
             
                    if ActiveRecord::VERSION::MAJOR >= 7
         
     | 
| 
       17 
18 
     | 
    
         
             
                      if ActiveRecord.default_timezone == :local
         
     | 
| 
         @@ -23,7 +23,7 @@ module Groupdate 
     | 
|
| 
       23 
23 
     | 
    
         
             
                      when :week
         
     | 
| 
       24 
24 
     | 
    
         
             
                        ["(DATE_TRUNC('day', #{day_start_column} - INTERVAL '1 day' * ((? + EXTRACT(DOW FROM #{day_start_column})::integer) % 7)) + INTERVAL ?)::date", time_zone, day_start_interval, 13 - week_start, time_zone, day_start_interval, day_start_interval]
         
     | 
| 
       25 
25 
     | 
    
         
             
                      when :custom
         
     | 
| 
       26 
     | 
    
         
            -
                        if @ 
     | 
| 
      
 26 
     | 
    
         
            +
                        if @adapter_name == "Redshift"
         
     | 
| 
       27 
27 
     | 
    
         
             
                          ["TIMESTAMP 'epoch' + (FLOOR(EXTRACT(EPOCH FROM #{column}::timestamp) / ?) * ?) * INTERVAL '1 second'", n_seconds, n_seconds]
         
     | 
| 
       28 
28 
     | 
    
         
             
                        else
         
     | 
| 
       29 
29 
     | 
    
         
             
                          ["TO_TIMESTAMP(FLOOR(EXTRACT(EPOCH FROM #{column}::timestamptz) / ?) * ?)", n_seconds, n_seconds]
         
     | 
    
        data/lib/groupdate/magic.rb
    CHANGED
    
    | 
         @@ -180,12 +180,13 @@ module Groupdate 
     | 
|
| 
       180 
180 
     | 
    
         
             
                  end
         
     | 
| 
       181 
181 
     | 
    
         | 
| 
       182 
182 
     | 
    
         
             
                  def time_zone_support?(relation)
         
     | 
| 
       183 
     | 
    
         
            -
                     
     | 
| 
       184 
     | 
    
         
            -
                       
     | 
| 
       185 
     | 
    
         
            -
             
     | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
             
     | 
| 
      
 183 
     | 
    
         
            +
                    relation.connection_pool.with_connection do |connection|
         
     | 
| 
      
 184 
     | 
    
         
            +
                      if connection.adapter_name.match?(/mysql|trilogy/i)
         
     | 
| 
      
 185 
     | 
    
         
            +
                        sql = relation.send(:sanitize_sql_array, ["SELECT CONVERT_TZ(NOW(), '+00:00', ?)", time_zone.tzinfo.name])
         
     | 
| 
      
 186 
     | 
    
         
            +
                        !connection.select_all(sql).to_a.first.values.first.nil?
         
     | 
| 
      
 187 
     | 
    
         
            +
                      else
         
     | 
| 
      
 188 
     | 
    
         
            +
                        true
         
     | 
| 
      
 189 
     | 
    
         
            +
                      end
         
     | 
| 
       189 
190 
     | 
    
         
             
                    end
         
     | 
| 
       190 
191 
     | 
    
         
             
                  end
         
     | 
| 
       191 
192 
     | 
    
         | 
| 
         @@ -203,7 +204,7 @@ module Groupdate 
     | 
|
| 
       203 
204 
     | 
    
         
             
                  def self.generate_relation(relation, field:, **options)
         
     | 
| 
       204 
205 
     | 
    
         
             
                    magic = Groupdate::Magic::Relation.new(**options)
         
     | 
| 
       205 
206 
     | 
    
         | 
| 
       206 
     | 
    
         
            -
                    adapter_name = relation. 
     | 
| 
      
 207 
     | 
    
         
            +
                    adapter_name = relation.connection_pool.with_connection { |c| c.adapter_name }
         
     | 
| 
       207 
208 
     | 
    
         
             
                    adapter = Groupdate.adapters[adapter_name]
         
     | 
| 
       208 
209 
     | 
    
         
             
                    raise Groupdate::Error, "Connection adapter not supported: #{adapter_name}" unless adapter
         
     | 
| 
       209 
210 
     | 
    
         | 
| 
         @@ -221,7 +222,8 @@ module Groupdate 
     | 
|
| 
       221 
222 
     | 
    
         
             
                        time_range: magic.time_range,
         
     | 
| 
       222 
223 
     | 
    
         
             
                        week_start: magic.week_start,
         
     | 
| 
       223 
224 
     | 
    
         
             
                        day_start: magic.day_start,
         
     | 
| 
       224 
     | 
    
         
            -
                        n_seconds: magic.n_seconds
         
     | 
| 
      
 225 
     | 
    
         
            +
                        n_seconds: magic.n_seconds,
         
     | 
| 
      
 226 
     | 
    
         
            +
                        adapter_name: adapter_name
         
     | 
| 
       225 
227 
     | 
    
         
             
                      ).generate
         
     | 
| 
       226 
228 
     | 
    
         | 
| 
       227 
229 
     | 
    
         
             
                    # add Groupdate info
         
     | 
| 
         @@ -251,7 +253,7 @@ module Groupdate 
     | 
|
| 
       251 
253 
     | 
    
         
             
                    def resolve_column(relation, column)
         
     | 
| 
       252 
254 
     | 
    
         
             
                      node = relation.send(:relation).send(:arel_columns, [column]).first
         
     | 
| 
       253 
255 
     | 
    
         
             
                      node = Arel::Nodes::SqlLiteral.new(node) if node.is_a?(String)
         
     | 
| 
       254 
     | 
    
         
            -
                      relation. 
     | 
| 
      
 256 
     | 
    
         
            +
                      relation.connection_pool.with_connection { |c| c.visitor.accept(node, Arel::Collectors::SQLString.new).value }
         
     | 
| 
       255 
257 
     | 
    
         
             
                    end
         
     | 
| 
       256 
258 
     | 
    
         
             
                  end
         
     | 
| 
       257 
259 
     | 
    
         | 
    
        data/lib/groupdate/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: groupdate
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version
         
     | 
| 
       4 
     | 
    
         
            -
              version: 6.5. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 6.5.1
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors:
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Andrew Kane
         
     | 
| 
       8 
8 
     | 
    
         
             
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024-10- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-10-08 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activesupport
         
     |