groupdate 6.4.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 +13 -4
- data/LICENSE.txt +1 -1
- data/README.md +6 -16
- data/lib/groupdate/adapters/base_adapter.rb +2 -1
- data/lib/groupdate/adapters/postgresql_adapter.rb +1 -1
- data/lib/groupdate/enumerable.rb +2 -2
- data/lib/groupdate/magic.rb +13 -11
- data/lib/groupdate/version.rb +1 -1
- metadata +6 -6
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
@@ -1,3 +1,12 @@
|
|
1
|
+
## 6.5.1 (2024-10-07)
|
2
|
+
|
3
|
+
- Fixed connection leasing for Active Record 7.2+
|
4
|
+
|
5
|
+
## 6.5.0 (2024-10-01)
|
6
|
+
|
7
|
+
- Added support for Active Record 8
|
8
|
+
- Dropped support for Ruby < 3.1 and Active Record < 7
|
9
|
+
|
1
10
|
## 6.4.0 (2023-09-13)
|
2
11
|
|
3
12
|
- Added support for Trilogy
|
@@ -173,7 +182,7 @@ Breaking changes
|
|
173
182
|
- Added `default_value` option
|
174
183
|
- Accept symbol for `format` option
|
175
184
|
- Raise `ArgumentError` if no field specified
|
176
|
-
- Added support for
|
185
|
+
- Added support for Active Record 5 beta
|
177
186
|
|
178
187
|
## 2.5.0 (2015-09-29)
|
179
188
|
|
@@ -187,18 +196,18 @@ Breaking changes
|
|
187
196
|
- Added `carry_forward` option
|
188
197
|
- Added `series: false` option for arrays and hashes
|
189
198
|
- Fixed issue w/ Brasilia Summer Time
|
190
|
-
- Fixed issues w/
|
199
|
+
- Fixed issues w/ Active Record 4.2
|
191
200
|
|
192
201
|
## 2.3.0 (2014-08-31)
|
193
202
|
|
194
|
-
- Raise error when ActiveRecord::Base.default_timezone is not `:utc`
|
203
|
+
- Raise error when `ActiveRecord::Base.default_timezone` is not `:utc`
|
195
204
|
- Added `day_of_month`
|
196
205
|
- Added `month_of_year`
|
197
206
|
- Do not quote column name
|
198
207
|
|
199
208
|
## 2.2.1 (2014-06-23)
|
200
209
|
|
201
|
-
- Fixed
|
210
|
+
- Fixed Active Record 3 associations
|
202
211
|
|
203
212
|
## 2.2.0 (2014-06-22)
|
204
213
|
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -11,11 +11,11 @@ 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
|
|
18
|
-
[](https://github.com/ankane/groupdate/actions)
|
19
19
|
|
20
20
|
## Installation
|
21
21
|
|
@@ -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
|
|
@@ -280,18 +282,6 @@ If your application’s time zone is set to something other than `Etc/UTC` (the
|
|
280
282
|
Groupdate.time_zone = false
|
281
283
|
```
|
282
284
|
|
283
|
-
## Upgrading
|
284
|
-
|
285
|
-
### 6.0
|
286
|
-
|
287
|
-
Groupdate 6.0 protects against unsafe input by default. For non-attribute arguments, use:
|
288
|
-
|
289
|
-
```ruby
|
290
|
-
User.group_by_day(Arel.sql(known_safe_value)).count
|
291
|
-
```
|
292
|
-
|
293
|
-
Also, the `dates` option has been removed.
|
294
|
-
|
295
285
|
## History
|
296
286
|
|
297
287
|
View the [changelog](https://github.com/ankane/groupdate/blob/master/CHANGELOG.md)
|
@@ -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/enumerable.rb
CHANGED
@@ -5,7 +5,7 @@ module Enumerable
|
|
5
5
|
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 0)" if args.any?
|
6
6
|
Groupdate::Magic::Enumerable.group_by(self, period, options, &block)
|
7
7
|
elsif respond_to?(:scoping)
|
8
|
-
scoping {
|
8
|
+
scoping { klass.group_by_period(period, *args, **options, &block) }
|
9
9
|
else
|
10
10
|
raise ArgumentError, "no block given"
|
11
11
|
end
|
@@ -19,7 +19,7 @@ module Enumerable
|
|
19
19
|
Groupdate::Magic.validate_period(period, options.delete(:permit))
|
20
20
|
send("group_by_#{period}", **options, &block)
|
21
21
|
else
|
22
|
-
scoping {
|
22
|
+
scoping { klass.group_by_period(period, *args, **options, &block) }
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
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
|
@@ -238,7 +240,7 @@ module Groupdate
|
|
238
240
|
def validate_column(column)
|
239
241
|
unless column.is_a?(Symbol) || column.is_a?(Arel::Nodes::SqlLiteral)
|
240
242
|
column = column.to_s
|
241
|
-
unless /\A\w+(\.\w+)?\z/i.match(column)
|
243
|
+
unless /\A\w+(\.\w+)?\z/i.match?(column)
|
242
244
|
raise ActiveRecord::UnknownAttributeReference, "Query method called with non-attribute argument(s): #{column.inspect}. Use Arel.sql() for known-safe values."
|
243
245
|
end
|
244
246
|
end
|
@@ -251,13 +253,13 @@ 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
|
|
258
260
|
# allow any options to keep flexible for future
|
259
261
|
def self.process_result(relation, result, **options)
|
260
|
-
relation.groupdate_values.
|
262
|
+
relation.groupdate_values.reverse_each do |gv|
|
261
263
|
result = gv.perform(relation, result, default_value: options[:default_value])
|
262
264
|
end
|
263
265
|
result
|
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.
|
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:
|
11
|
+
date: 2024-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '7'
|
27
27
|
description:
|
28
28
|
email: andrew@ankane.org
|
29
29
|
executables: []
|
@@ -58,14 +58,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '3'
|
61
|
+
version: '3.1'
|
62
62
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
64
|
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '0'
|
67
67
|
requirements: []
|
68
|
-
rubygems_version: 3.
|
68
|
+
rubygems_version: 3.5.16
|
69
69
|
signing_key:
|
70
70
|
specification_version: 4
|
71
71
|
summary: The simplest way to group temporal data
|