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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ef9a0ee3177e94a0e797036221d6e33b124e41f7f867fe8b0904a24bd7cf741
4
- data.tar.gz: 73ef98496e157ba77bc8afb226c625dc9f117347b676eb39d767f4d55023309a
3
+ metadata.gz: f55bd15dca1c101b40370cd1fb1f82eca0567fb73511849135a1989fa4a6a11a
4
+ data.tar.gz: 7299ac70d10043b1f95de4885bb02683f55b33f1b075c7e5aced130ef8a6d979
5
5
  SHA512:
6
- metadata.gz: b38cacba795f7f0e0430fa1c1935b5e2aa6556926b70533966e912f5a7110291bb2a5f6542c37c6fd7bb996cf973db5241eb7299a8c664e327026fb702cf191a
7
- data.tar.gz: 393f55d1892c6b65cbe51608aaee4f7e1f2a06067637196a1d6ed82e69434ebb10169553308f21cb8738d06513e19eb505657ccea8d47544da85ca3c77eff02d
6
+ metadata.gz: 9c1d74da58305bdf89f9c5196ef730712463e4c001ca4592a2f4d1b60d88deb5ca3ba6650f19d307a56e6ffc465f551b7d70ea14008c0445cad8d9f056e751f5
7
+ data.tar.gz: 8ce0e0a7b317214b1eb31913083d9f8f6657b62255617752432c6ede1d3fb1e83cab133bc7cdd725c11522f4d2548ebef2df6bff271f06d02dfa6302e0954d77
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 6.5.1 (2024-10-07)
2
+
3
+ - Fixed connection leasing for Active Record 7.2+
4
+
1
5
  ## 6.5.0 (2024-10-01)
2
6
 
3
7
  - Added support for Active Record 8
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
- ### For MySQL
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 @relation.connection.adapter_name == "Redshift"
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]
@@ -180,12 +180,13 @@ module Groupdate
180
180
  end
181
181
 
182
182
  def time_zone_support?(relation)
183
- if relation.connection.adapter_name.match?(/mysql/i)
184
- # need to call klass for Rails < 5.2
185
- sql = relation.klass.send(:sanitize_sql_array, ["SELECT CONVERT_TZ(NOW(), '+00:00', ?)", time_zone.tzinfo.name])
186
- !relation.connection.select_all(sql).to_a.first.values.first.nil?
187
- else
188
- true
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.connection.adapter_name
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.connection.visitor.accept(node, Arel::Collectors::SQLString.new).value
256
+ relation.connection_pool.with_connection { |c| c.visitor.accept(node, Arel::Collectors::SQLString.new).value }
255
257
  end
256
258
  end
257
259
 
@@ -1,3 +1,3 @@
1
1
  module Groupdate
2
- VERSION = "6.5.0"
2
+ VERSION = "6.5.1"
3
3
  end
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.0
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-01 00:00:00.000000000 Z
11
+ date: 2024-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport