arel_extensions 1.3.7 → 1.3.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +16 -0
- data/README.md +12 -0
- data/Rakefile +7 -0
- data/dev/compose.yaml +29 -0
- data/gemfiles/rails7_1.gemfile +22 -0
- data/lib/arel_extensions/helpers.rb +11 -5
- data/lib/arel_extensions/nodes/concat.rb +1 -1
- data/lib/arel_extensions/nodes/json.rb +6 -2
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/to_sql.rb +7 -1
- data/lib/arel_extensions.rb +7 -0
- data/test/arelx_test_helper.rb +0 -4
- data/test/with_ar/all_agnostic_test.rb +9 -2
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db1001f3712bc329382b77345bde00ff5c1a074a6ea757841b40fcaa230f9c08
|
4
|
+
data.tar.gz: de6cb9e86796ac091ae148f80888a4093ecbe0df9312ad5cbbcd16f7efc6b8f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f225335f190b18b56c88e64cea0eef39771f6e937bebd57d814a6c4562c96236e2708f905eef4ec80801c9d6c475aebc717b99c265c2cbccbda46b30e0798786
|
7
|
+
data.tar.gz: e89e25e2336dee7d1f617f05ceb30df609dfdca52ff65e73e86fc2baaff91c1ae8d51e8d50510ba0981cc8bac9d62327164204957afbf18a1cf1c43728a3bf5d
|
data/.github/workflows/ruby.yml
CHANGED
@@ -13,12 +13,16 @@ jobs:
|
|
13
13
|
fail-fast: false
|
14
14
|
matrix:
|
15
15
|
versions: [
|
16
|
+
{ruby: '3.2', rails: 7_1, arelx: 2},
|
16
17
|
{ruby: '3.2', rails: 7, arelx: 2},
|
17
18
|
{ruby: '3.2', rails: 6_1, arelx: 2},
|
19
|
+
{ruby: '3.1', rails: 7_1, arelx: 2},
|
18
20
|
{ruby: '3.1', rails: 7, arelx: 2},
|
19
21
|
{ruby: '3.1', rails: 6_1, arelx: 2},
|
22
|
+
{ruby: '3.0', rails: 7_1, arelx: 2},
|
20
23
|
{ruby: '3.0', rails: 7, arelx: 2},
|
21
24
|
{ruby: '3.0', rails: 6_1, arelx: 2},
|
25
|
+
{ruby: '2.7', rails: 7_1, arelx: 2},
|
22
26
|
{ruby: '2.7', rails: 7, arelx: 2},
|
23
27
|
{ruby: '2.7', rails: 6_1, arelx: 2},
|
24
28
|
{ruby: '2.7', rails: 6, arelx: 2},
|
@@ -68,12 +72,16 @@ jobs:
|
|
68
72
|
fail-fast: false
|
69
73
|
matrix:
|
70
74
|
versions: [
|
75
|
+
{ruby: '3.2', rails: 7_1, arelx: 2},
|
71
76
|
{ruby: '3.2', rails: 7, arelx: 2},
|
72
77
|
{ruby: '3.2', rails: 6_1, arelx: 2},
|
78
|
+
{ruby: '3.1', rails: 7_1, arelx: 2},
|
73
79
|
{ruby: '3.1', rails: 7, arelx: 2},
|
74
80
|
{ruby: '3.1', rails: 6_1, arelx: 2},
|
81
|
+
{ruby: '3.0', rails: 7_1, arelx: 2},
|
75
82
|
{ruby: '3.0', rails: 7, arelx: 2},
|
76
83
|
{ruby: '3.0', rails: 6_1, arelx: 2},
|
84
|
+
{ruby: '2.7', rails: 7_1, arelx: 2},
|
77
85
|
{ruby: '2.7', rails: 7, arelx: 2},
|
78
86
|
{ruby: '2.7', rails: 6_1, arelx: 2},
|
79
87
|
{ruby: '2.7', rails: 6, arelx: 2},
|
@@ -124,12 +132,16 @@ jobs:
|
|
124
132
|
fail-fast: false
|
125
133
|
matrix:
|
126
134
|
versions: [
|
135
|
+
{ruby: '3.2', rails: 7_1, arelx: 2},
|
127
136
|
{ruby: '3.2', rails: 7, arelx: 2},
|
128
137
|
{ruby: '3.2', rails: 6_1, arelx: 2},
|
138
|
+
{ruby: '3.1', rails: 7_1, arelx: 2},
|
129
139
|
{ruby: '3.1', rails: 7, arelx: 2},
|
130
140
|
{ruby: '3.1', rails: 6_1, arelx: 2},
|
141
|
+
{ruby: '3.0', rails: 7_1, arelx: 2},
|
131
142
|
{ruby: '3.0', rails: 7, arelx: 2},
|
132
143
|
{ruby: '3.0', rails: 6_1, arelx: 2},
|
144
|
+
{ruby: '2.7', rails: 7_1, arelx: 2},
|
133
145
|
{ruby: '2.7', rails: 7, arelx: 2},
|
134
146
|
{ruby: '2.7', rails: 6_1, arelx: 2},
|
135
147
|
{ruby: '2.7', rails: 6, arelx: 2},
|
@@ -205,12 +217,16 @@ jobs:
|
|
205
217
|
fail-fast: false
|
206
218
|
matrix:
|
207
219
|
versions: [
|
220
|
+
{ruby: '3.2', rails: 7_1, arelx: 2},
|
208
221
|
{ruby: '3.2', rails: 7, arelx: 2},
|
209
222
|
{ruby: '3.2', rails: 6_1, arelx: 2},
|
223
|
+
{ruby: '3.1', rails: 7_1, arelx: 2},
|
210
224
|
{ruby: '3.1', rails: 7, arelx: 2},
|
211
225
|
{ruby: '3.1', rails: 6_1, arelx: 2},
|
226
|
+
{ruby: '3.0', rails: 7_1, arelx: 2},
|
212
227
|
{ruby: '3.0', rails: 7, arelx: 2},
|
213
228
|
{ruby: '3.0', rails: 6_1, arelx: 2},
|
229
|
+
{ruby: '2.7', rails: 7_1, arelx: 2},
|
214
230
|
{ruby: '2.7', rails: 7, arelx: 2},
|
215
231
|
{ruby: '2.7', rails: 6_1, arelx: 2},
|
216
232
|
{ruby: '2.7', rails: 6, arelx: 2},
|
data/README.md
CHANGED
@@ -771,3 +771,15 @@ bundle exec rake test:to_sql
|
|
771
771
|
|
772
772
|
Refer to the [Version Compatibility](#version-compatibility) section to correctly
|
773
773
|
set your gemfile.
|
774
|
+
|
775
|
+
### MariaDB and Postgres
|
776
|
+
|
777
|
+
We provide a `docker compose` to set up some databases for testing:
|
778
|
+
|
779
|
+
```bash
|
780
|
+
docker-compose -f dev/compose.yaml up
|
781
|
+
```
|
782
|
+
|
783
|
+
⚠️ Note: localization tests will fail for postgresql because the image is made
|
784
|
+
for `en_US.UTF`. We should fix it later, but for the time being the CI works
|
785
|
+
correctly for these tests, so you can safely ignore them for the time being.
|
data/Rakefile
CHANGED
@@ -48,3 +48,10 @@ end
|
|
48
48
|
# Make sure the adapter test evaluates the env setting task
|
49
49
|
task "test_#{adapter}" => ["#{adapter}:env", "test:#{adapter}"]
|
50
50
|
end
|
51
|
+
|
52
|
+
# Useful shorthands.
|
53
|
+
namespace :test do
|
54
|
+
task :sql => :to_sql
|
55
|
+
task :pg => :postgresql
|
56
|
+
task :postgres => :postgresql
|
57
|
+
end
|
data/dev/compose.yaml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
name: arelx-dbs
|
2
|
+
services:
|
3
|
+
mariadb:
|
4
|
+
image: mariadb:11.0
|
5
|
+
container_name: mariadb
|
6
|
+
environment:
|
7
|
+
MARIADB_DATABASE: arelx_test
|
8
|
+
MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true
|
9
|
+
ports:
|
10
|
+
- "3306:3306"
|
11
|
+
healthcheck:
|
12
|
+
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
|
13
|
+
interval: 10s
|
14
|
+
timeout: 5s
|
15
|
+
retries: 3
|
16
|
+
postgres:
|
17
|
+
image: postgres:15
|
18
|
+
container_name: postgres
|
19
|
+
environment:
|
20
|
+
POSTGRES_USER: postgres
|
21
|
+
POSTGRES_PASSWORD: secret
|
22
|
+
POSTGRES_DB: arelx_test
|
23
|
+
ports:
|
24
|
+
- "5432:5432"
|
25
|
+
healthcheck:
|
26
|
+
test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"]
|
27
|
+
interval: 10s
|
28
|
+
timeout: 5s
|
29
|
+
retries: 3
|
@@ -0,0 +1,22 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'rails', '~> 7.1'
|
4
|
+
|
5
|
+
group :development, :test do
|
6
|
+
gem 'activesupport', '~> 7.1'
|
7
|
+
gem 'activemodel', '~> 7.1'
|
8
|
+
gem 'activerecord', '~> 7.1'
|
9
|
+
|
10
|
+
gem 'sqlite3', '~> 1.6', platforms: [:mri]
|
11
|
+
gem 'mysql2', '~>0.5', platforms: [:mri]
|
12
|
+
gem 'pg', '~> 1.5', platforms: [:mri]
|
13
|
+
|
14
|
+
gem 'tiny_tds', platforms: %i[mri mingw x64_mingw mswin]
|
15
|
+
gem 'activerecord-sqlserver-adapter', '~> 7.1.0.beta1', platforms: %i[mri mingw x64_mingw mswin]
|
16
|
+
gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw]
|
17
|
+
|
18
|
+
gem 'ruby-oci8', platforms: %i[mri mswin mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
|
+
gem 'activerecord-oracle_enhanced-adapter', '~> 7.0.0' if ENV.has_key? 'ORACLE_HOME'
|
20
|
+
end
|
21
|
+
|
22
|
+
gemspec path: Dir.pwd
|
@@ -20,7 +20,8 @@ module ArelExtensions
|
|
20
20
|
rescue NoMethodError
|
21
21
|
nil
|
22
22
|
rescue => e
|
23
|
-
warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of_via_arel_table`\n#{e.class}
|
23
|
+
warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of_via_arel_table`\n#{e.class}")
|
24
|
+
warn(e.backtrace)
|
24
25
|
nil
|
25
26
|
end
|
26
27
|
|
@@ -33,10 +34,14 @@ module ArelExtensions
|
|
33
34
|
column_of_via_arel_table(table_name, column_name)
|
34
35
|
else
|
35
36
|
if pool.respond_to?(:pool_config)
|
36
|
-
pool.pool_config.
|
37
|
-
|
37
|
+
if pool.pool_config.respond_to?(:schema_reflection) # activerecord >= 7.1
|
38
|
+
pool.pool_config.schema_reflection.columns_hash(ActiveRecord::Base.connection, table_name)[column_name]
|
39
|
+
else # activerecord < 7.1
|
40
|
+
pool.pool_config.schema_cache.columns_hash(table_name)[column_name]
|
41
|
+
end
|
42
|
+
elsif pool.respond_to?(:schema_cache) # activerecord < 6.1
|
38
43
|
pool.schema_cache.columns_hash(table_name)[column_name]
|
39
|
-
else
|
44
|
+
else # activerecord < 5.0
|
40
45
|
column_of_via_arel_table(table_name, column_name)
|
41
46
|
end
|
42
47
|
end
|
@@ -45,7 +50,8 @@ module ArelExtensions
|
|
45
50
|
rescue ActiveRecord::StatementInvalid
|
46
51
|
nil
|
47
52
|
rescue => e
|
48
|
-
warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of`\n#{e.class}
|
53
|
+
warn("Warning: Unexpected exception caught while fetching column name for #{table_name}.#{column_name} in `column_of`\n#{e.class}")
|
54
|
+
warn(e.backtrace)
|
49
55
|
nil
|
50
56
|
end
|
51
57
|
end
|
@@ -16,7 +16,7 @@ module ArelExtensions::Nodes
|
|
16
16
|
if b.is_a?(Arel::Nodes::Quoted) && b.expr == ''
|
17
17
|
res
|
18
18
|
elsif res.last && res.last.is_a?(Arel::Nodes::Quoted) && b.is_a?(Arel::Nodes::Quoted)
|
19
|
-
res[-1] = Arel.quoted(res.last.expr + b.expr)
|
19
|
+
res[-1] = Arel.quoted(res.last.expr.to_s + b.expr.to_s)
|
20
20
|
else
|
21
21
|
res << b
|
22
22
|
end
|
@@ -18,8 +18,12 @@ module ArelExtensions
|
|
18
18
|
JsonSet.new(self, key, value)
|
19
19
|
end
|
20
20
|
|
21
|
-
def group as_array = true, orders = nil
|
22
|
-
|
21
|
+
def group as_array = true, orders = nil, distinct: false
|
22
|
+
if distinct
|
23
|
+
JsonGroup.new(Arel::Nodes::NamedFunction.new('DISTINCT', [self]), as_array, orders)
|
24
|
+
else
|
25
|
+
JsonGroup.new(self, as_array, orders)
|
26
|
+
end
|
23
27
|
end
|
24
28
|
|
25
29
|
def hash
|
@@ -9,7 +9,13 @@ module ArelExtensions
|
|
9
9
|
Arel.quoted('"') \
|
10
10
|
+ expr
|
11
11
|
.coalesce('')
|
12
|
-
.replace('\\', '\\\\')
|
12
|
+
.replace('\\', '\\\\')
|
13
|
+
.replace('"', '\"')
|
14
|
+
.replace("\b", '\b')
|
15
|
+
.replace("\f", '\f')
|
16
|
+
.replace("\n", '\n')
|
17
|
+
.replace("\r", '\r')
|
18
|
+
.replace("\t", '\t') \
|
13
19
|
+ '"'
|
14
20
|
end
|
15
21
|
|
data/lib/arel_extensions.rb
CHANGED
@@ -256,6 +256,13 @@ end
|
|
256
256
|
|
257
257
|
class Arel::Table
|
258
258
|
alias_method(:old_alias, :alias) rescue nil
|
259
|
+
|
260
|
+
# activerecord 7.1 removed the alias. We might need to remove our dependency
|
261
|
+
# on the alias if it proves problematic.
|
262
|
+
if !self.respond_to?(:table_name)
|
263
|
+
alias :table_name :name
|
264
|
+
end
|
265
|
+
|
259
266
|
def alias(name = "#{self.name}_2")
|
260
267
|
if name.present?
|
261
268
|
Arel::Nodes::TableAlias.new(self, name)
|
data/test/arelx_test_helper.rb
CHANGED
@@ -675,15 +675,22 @@ module ArelExtensions
|
|
675
675
|
end
|
676
676
|
|
677
677
|
def test_date_duration
|
678
|
+
# When user `nilly` is created, with an explicit `created_at: nil`,
|
679
|
+
# activerecord will give it the current date.
|
680
|
+
#
|
681
|
+
# So depending on the month when we run this test, we will get different
|
682
|
+
# results for `User.where(@created_at.month.eq('05'))`.
|
683
|
+
count_for_may = Time.now.month == 5 ? 10 : 9
|
684
|
+
|
678
685
|
# Year
|
679
686
|
assert_equal 2016, t(@lucas, @created_at.year).to_i
|
680
687
|
assert_equal 0, User.where(@created_at.year.eq('2012')).count
|
681
688
|
# Month
|
682
689
|
assert_equal 5, t(@camille, @created_at.month).to_i
|
683
|
-
assert_equal
|
690
|
+
assert_equal count_for_may, User.where(@created_at.month.eq('05')).count
|
684
691
|
# Week
|
685
692
|
assert_equal(@env_db == 'mssql' ? 22 : 21, t(@arthur, @created_at.week).to_i)
|
686
|
-
assert_equal
|
693
|
+
assert_equal count_for_may, User.where(@created_at.month.eq('05')).count
|
687
694
|
# Day
|
688
695
|
assert_equal 23, t(@laure, @created_at.day).to_i
|
689
696
|
assert_equal 0, User.where(@created_at.day.eq('05')).count
|
data/version_v1.rb
CHANGED
data/version_v2.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yann Azoury
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2023-
|
13
|
+
date: 2023-11-14 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: arel
|
@@ -79,6 +79,7 @@ files:
|
|
79
79
|
- TODO
|
80
80
|
- appveyor.yml
|
81
81
|
- arel_extensions.gemspec
|
82
|
+
- dev/compose.yaml
|
82
83
|
- functions.html
|
83
84
|
- gemfiles/rails3.gemfile
|
84
85
|
- gemfiles/rails4_2.gemfile
|
@@ -88,6 +89,7 @@ files:
|
|
88
89
|
- gemfiles/rails6.gemfile
|
89
90
|
- gemfiles/rails6_1.gemfile
|
90
91
|
- gemfiles/rails7.gemfile
|
92
|
+
- gemfiles/rails7_1.gemfile
|
91
93
|
- gemspecs/arel_extensions-v1.gemspec
|
92
94
|
- gemspecs/arel_extensions-v2.gemspec
|
93
95
|
- generate_gems.sh
|