arel_extensions 2.1.7 → 2.1.9
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/.github/workflows/publish.yml +29 -0
- data/.github/workflows/release.yml +30 -0
- data/.github/workflows/ruby.yml +16 -15
- data/NEWS.md +33 -3
- data/README.md +15 -3
- data/Rakefile +7 -0
- data/bin/build +15 -0
- data/bin/publish +8 -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/postgresql.rb +2 -2
- data/lib/arel_extensions/visitors/to_sql.rb +7 -1
- data/lib/arel_extensions.rb +27 -0
- data/test/arelx_test_helper.rb +0 -4
- data/test/with_ar/all_agnostic_test.rb +10 -3
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +9 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf8950e5b07e10442a88c5c660495503f6168948d63fa4250ccdf089e52b4dc6
|
|
4
|
+
data.tar.gz: ee6eb65da6146558100863b917b15b19a2ddea07cf4c426460bef12fa02437e3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d5cbf62523776e12434328e1ad23302d71bf5ff35665830bdf95419fc878f118515ba184a914f4c59ffe939c843856bb48007f302d9269df374cc5f41e59925b
|
|
7
|
+
data.tar.gz: 575f1b5a93464e92ba581b2adc5d4190c0ad2b88d62bf2b8559a58a9a032ee9d6500f716a81474d9fb3127a5485f110013e3b778a20c91584e52c672eef992b9
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: "Publish Gems"
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
publish_gems:
|
|
8
|
+
name: Publish to Rubygems
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v3
|
|
12
|
+
- name: setup ruby 3.2
|
|
13
|
+
uses: ruby/setup-ruby@v1
|
|
14
|
+
with:
|
|
15
|
+
ruby-version: 3.2
|
|
16
|
+
- name: Fetch Github Release Asset
|
|
17
|
+
uses: dsaltares/fetch-gh-release-asset@master
|
|
18
|
+
with:
|
|
19
|
+
file: "arel_extensions.*.gem"
|
|
20
|
+
regex: true
|
|
21
|
+
token: ${{ secrets.GITHUB_TOKEN }}
|
|
22
|
+
- name: List gems
|
|
23
|
+
run: ls -l *.gem
|
|
24
|
+
- name: Release Gems
|
|
25
|
+
uses: cadwallion/publish-rubygems-action@master
|
|
26
|
+
env:
|
|
27
|
+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
|
|
28
|
+
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
|
29
|
+
RELEASE_COMMAND: bin/publish
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
on:
|
|
3
|
+
workflow_run:
|
|
4
|
+
workflows: ["Build and Test"]
|
|
5
|
+
branches: [master]
|
|
6
|
+
types:
|
|
7
|
+
- completed
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build_gems:
|
|
11
|
+
name: Build Gemfiles
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v3
|
|
15
|
+
- name: setup ruby 3.2
|
|
16
|
+
uses: ruby/setup-ruby@v1
|
|
17
|
+
with:
|
|
18
|
+
ruby-version: 3.2
|
|
19
|
+
- name: build gems
|
|
20
|
+
run: |
|
|
21
|
+
bin/build
|
|
22
|
+
- name: release
|
|
23
|
+
uses: softprops/action-gh-release@v1
|
|
24
|
+
with:
|
|
25
|
+
tag_name: ${{ github.ref }}-${{ steps.vars.outputs.sha_short }}
|
|
26
|
+
draft: true
|
|
27
|
+
files: |
|
|
28
|
+
./arel_extensions-*.gem
|
|
29
|
+
env:
|
|
30
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
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},
|
|
@@ -45,9 +49,6 @@ jobs:
|
|
|
45
49
|
run: |
|
|
46
50
|
sudo apt-get update -q
|
|
47
51
|
sudo apt-get install -y freetds-dev
|
|
48
|
-
- name: Update system-wide gems
|
|
49
|
-
if: ${{ !contains(fromJson('["2.5", "jruby-9.2"]'), matrix.versions.ruby) }}
|
|
50
|
-
run: gem update --system --no-document
|
|
51
52
|
- name: Setup Gemfile for arelx 2.x
|
|
52
53
|
if: ${{ matrix.versions.arelx == 2 }}
|
|
53
54
|
run: |
|
|
@@ -68,12 +69,16 @@ jobs:
|
|
|
68
69
|
fail-fast: false
|
|
69
70
|
matrix:
|
|
70
71
|
versions: [
|
|
72
|
+
{ruby: '3.2', rails: 7_1, arelx: 2},
|
|
71
73
|
{ruby: '3.2', rails: 7, arelx: 2},
|
|
72
74
|
{ruby: '3.2', rails: 6_1, arelx: 2},
|
|
75
|
+
{ruby: '3.1', rails: 7_1, arelx: 2},
|
|
73
76
|
{ruby: '3.1', rails: 7, arelx: 2},
|
|
74
77
|
{ruby: '3.1', rails: 6_1, arelx: 2},
|
|
78
|
+
{ruby: '3.0', rails: 7_1, arelx: 2},
|
|
75
79
|
{ruby: '3.0', rails: 7, arelx: 2},
|
|
76
80
|
{ruby: '3.0', rails: 6_1, arelx: 2},
|
|
81
|
+
{ruby: '2.7', rails: 7_1, arelx: 2},
|
|
77
82
|
{ruby: '2.7', rails: 7, arelx: 2},
|
|
78
83
|
{ruby: '2.7', rails: 6_1, arelx: 2},
|
|
79
84
|
{ruby: '2.7', rails: 6, arelx: 2},
|
|
@@ -101,9 +106,6 @@ jobs:
|
|
|
101
106
|
run: |
|
|
102
107
|
sudo apt-get update -q
|
|
103
108
|
sudo apt-get install -y freetds-dev
|
|
104
|
-
- name: Update system-wide gems
|
|
105
|
-
if: ${{ !contains(fromJson('["2.5", "jruby-9.2"]'), matrix.versions.ruby) }}
|
|
106
|
-
run: gem update --system --no-document
|
|
107
109
|
- name: Setup Gemfile
|
|
108
110
|
if: ${{ matrix.versions.arelx == 2 }}
|
|
109
111
|
run: |
|
|
@@ -124,12 +126,16 @@ jobs:
|
|
|
124
126
|
fail-fast: false
|
|
125
127
|
matrix:
|
|
126
128
|
versions: [
|
|
129
|
+
{ruby: '3.2', rails: 7_1, arelx: 2},
|
|
127
130
|
{ruby: '3.2', rails: 7, arelx: 2},
|
|
128
131
|
{ruby: '3.2', rails: 6_1, arelx: 2},
|
|
132
|
+
{ruby: '3.1', rails: 7_1, arelx: 2},
|
|
129
133
|
{ruby: '3.1', rails: 7, arelx: 2},
|
|
130
134
|
{ruby: '3.1', rails: 6_1, arelx: 2},
|
|
135
|
+
{ruby: '3.0', rails: 7_1, arelx: 2},
|
|
131
136
|
{ruby: '3.0', rails: 7, arelx: 2},
|
|
132
137
|
{ruby: '3.0', rails: 6_1, arelx: 2},
|
|
138
|
+
{ruby: '2.7', rails: 7_1, arelx: 2},
|
|
133
139
|
{ruby: '2.7', rails: 7, arelx: 2},
|
|
134
140
|
{ruby: '2.7', rails: 6_1, arelx: 2},
|
|
135
141
|
{ruby: '2.7', rails: 6, arelx: 2},
|
|
@@ -179,9 +185,6 @@ jobs:
|
|
|
179
185
|
run: |
|
|
180
186
|
sudo apt-get update -q
|
|
181
187
|
sudo apt-get install -y freetds-dev
|
|
182
|
-
- name: Update system-wide gems
|
|
183
|
-
if: ${{ !contains(fromJson('["2.5", "jruby-9.2"]'), matrix.versions.ruby) }}
|
|
184
|
-
run: gem update --system --no-document
|
|
185
188
|
- name: Setup Gemfile
|
|
186
189
|
if: ${{ matrix.versions.arelx == 2 }}
|
|
187
190
|
run: |
|
|
@@ -205,12 +208,16 @@ jobs:
|
|
|
205
208
|
fail-fast: false
|
|
206
209
|
matrix:
|
|
207
210
|
versions: [
|
|
211
|
+
{ruby: '3.2', rails: 7_1, arelx: 2},
|
|
208
212
|
{ruby: '3.2', rails: 7, arelx: 2},
|
|
209
213
|
{ruby: '3.2', rails: 6_1, arelx: 2},
|
|
214
|
+
{ruby: '3.1', rails: 7_1, arelx: 2},
|
|
210
215
|
{ruby: '3.1', rails: 7, arelx: 2},
|
|
211
216
|
{ruby: '3.1', rails: 6_1, arelx: 2},
|
|
217
|
+
{ruby: '3.0', rails: 7_1, arelx: 2},
|
|
212
218
|
{ruby: '3.0', rails: 7, arelx: 2},
|
|
213
219
|
{ruby: '3.0', rails: 6_1, arelx: 2},
|
|
220
|
+
{ruby: '2.7', rails: 7_1, arelx: 2},
|
|
214
221
|
{ruby: '2.7', rails: 7, arelx: 2},
|
|
215
222
|
{ruby: '2.7', rails: 6_1, arelx: 2},
|
|
216
223
|
{ruby: '2.7', rails: 6, arelx: 2},
|
|
@@ -252,9 +259,6 @@ jobs:
|
|
|
252
259
|
run: |
|
|
253
260
|
sudo apt-get update -q
|
|
254
261
|
sudo apt-get install -y freetds-dev
|
|
255
|
-
- name: Update system-wide gems
|
|
256
|
-
if: ${{ !contains(fromJson('["2.5", "jruby-9.2"]'), matrix.versions.ruby) }}
|
|
257
|
-
run: gem update --system --no-document
|
|
258
262
|
- name: Setup Gemfile
|
|
259
263
|
if: ${{ matrix.versions.arelx == 2 }}
|
|
260
264
|
run: |
|
|
@@ -321,9 +325,6 @@ jobs:
|
|
|
321
325
|
version: ${{ matrix.mssql }}
|
|
322
326
|
install: sqlengine, sqlclient, sqlpackage, localdb
|
|
323
327
|
sa-password: Password12!
|
|
324
|
-
- name: Update system-wide gems
|
|
325
|
-
if: ${{ !contains(fromJson('["2.5", "jruby-9.2"]'), matrix.versions.ruby) }}
|
|
326
|
-
run: gem update --system --no-document
|
|
327
328
|
- name: Setup Gemfile
|
|
328
329
|
if: ${{ matrix.versions.arelx == 2 }}
|
|
329
330
|
run: |
|
data/NEWS.md
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
# News
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## Release v2.1.9/v1.3.9
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
- Postgres:
|
|
8
|
+
- Datetime formatting in postgres now behaves like mysql: if the target
|
|
9
|
+
timezone is a string, we automatically consider that you're trying to
|
|
10
|
+
convert from `UTC`.
|
|
11
|
+
- Datetime casting will now automatically ask for a
|
|
12
|
+
`timestamp without timezone`, also aligning with the expected befavior
|
|
13
|
+
in mysql. This also makes casting work better with timezone conversion,
|
|
14
|
+
especially if you don't pass the timezone from which you're converting
|
|
15
|
+
to.
|
|
16
|
+
```ruby
|
|
17
|
+
scope
|
|
18
|
+
.select(Arel.quoted('2022-02-01 10:42:00')
|
|
19
|
+
.cast(:datetime)
|
|
20
|
+
.format_date('%Y/%m/%d %H:%M:%S', 'Europe/Paris')
|
|
21
|
+
.as('res'))
|
|
22
|
+
```
|
|
23
|
+
Will produce:
|
|
24
|
+
```sql
|
|
25
|
+
SELECT TO_CHAR(
|
|
26
|
+
CAST('2022-02-01 10:42:00' AS timestamp without time zone) AT TIME ZONE 'UTC' AT TIME ZONE 'Europe/Paris',
|
|
27
|
+
'YYYY/MM/DD HH24:MI:SS'
|
|
28
|
+
)
|
|
29
|
+
AS "res"
|
|
30
|
+
-- …
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Release v2.1.7/v1.3.7
|
|
4
34
|
|
|
5
35
|
### New Features
|
|
6
36
|
|
|
@@ -8,11 +38,11 @@
|
|
|
8
38
|
The actual behavior of `format` is inconsistent across DB vendors: in mysql we
|
|
9
39
|
can format dates and numbers with it, and in the other ones we only format
|
|
10
40
|
dates.
|
|
11
|
-
|
|
41
|
+
|
|
12
42
|
We're planning on normalizing this behavior. We want `format` to "cleverly"
|
|
13
43
|
format dates or numbers, and `format_date` / `format_number` to strictly
|
|
14
44
|
format dates / numbers.
|
|
15
|
-
|
|
45
|
+
|
|
16
46
|
The introduction of `format_date` is the first step in this direction.
|
|
17
47
|
|
|
18
48
|
## Release v2.1.6/v1.3.6
|
data/README.md
CHANGED
|
@@ -173,9 +173,9 @@ The second form accepts 2 kinds of values:
|
|
|
173
173
|
|
|
174
174
|
```ruby
|
|
175
175
|
t[:birthdate].format('%Y/%m/%d %H:%M:%S', 'posix/Pacific/Tahiti')
|
|
176
|
-
# => DATE_FORMAT(CONVERT_TZ(CAST(my_table.birthdate AS datetime), 'UTC', 'posix/Pacific/Tahiti'), '%Y/%m/%d %H:%i:%S')
|
|
177
|
-
# => TO_CHAR(CAST(my_table.birthdate AS timestamp with time zone) AT TIME ZONE 'posix/Pacific/Tahiti', 'YYYY/MM/DD HH24:MI:SS') ## PostgreSQL
|
|
178
|
-
# => CONVERT(datetime, my_table.birthdate) AT TIME ZONE 'UTC' AT TIME ZONE N'posix/Pacific/Tahiti'
|
|
176
|
+
# => DATE_FORMAT(CONVERT_TZ(CAST(my_table.birthdate AS datetime), 'UTC', 'posix/Pacific/Tahiti'), '%Y/%m/%d %H:%i:%S') ## MySQL
|
|
177
|
+
# => TO_CHAR(CAST(my_table.birthdate AS timestamp with time zone) AT TIME ZONE 'UTC' AT TIME ZONE 'posix/Pacific/Tahiti', 'YYYY/MM/DD HH24:MI:SS') ## PostgreSQL
|
|
178
|
+
# => CONVERT(datetime, my_table.birthdate) AT TIME ZONE 'UTC' AT TIME ZONE N'posix/Pacific/Tahiti' ## SQL Server (& truncated for clarity)
|
|
179
179
|
# ^^^^^^^^^^^^^^^^^^^^ 🚨 Invalid timezone for SQL Server. Explanation below.
|
|
180
180
|
```
|
|
181
181
|
|
|
@@ -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/bin/build
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#! /usr/bin/env sh
|
|
2
|
+
set -e
|
|
3
|
+
|
|
4
|
+
# VERSION ~> 1
|
|
5
|
+
echo "Packaging v1"
|
|
6
|
+
cp ./version_v1.rb lib/arel_extensions/version.rb
|
|
7
|
+
cp ./gemspecs/arel_extensions-v1.gemspec ./arel_extensions.gemspec
|
|
8
|
+
gem build ./arel_extensions.gemspec
|
|
9
|
+
|
|
10
|
+
# VERSION ~> 2
|
|
11
|
+
echo "Packaging v2"
|
|
12
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
|
13
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
|
14
|
+
gem build ./arel_extensions.gemspec
|
|
15
|
+
|
data/bin/publish
ADDED
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
|
|
@@ -190,7 +190,7 @@ module ArelExtensions
|
|
|
190
190
|
collector << ' AT TIME ZONE '
|
|
191
191
|
collector = visit Arel.quoted(dst_tz), collector
|
|
192
192
|
when String
|
|
193
|
-
collector <<
|
|
193
|
+
collector << ") AT TIME ZONE 'UTC' AT TIME ZONE "
|
|
194
194
|
collector = visit Arel.quoted(o.time_zone), collector
|
|
195
195
|
end
|
|
196
196
|
collector << COMMA
|
|
@@ -392,7 +392,7 @@ module ArelExtensions
|
|
|
392
392
|
when :number, :decimal, :float
|
|
393
393
|
'numeric'
|
|
394
394
|
when :datetime
|
|
395
|
-
'timestamp
|
|
395
|
+
'timestamp without time zone'
|
|
396
396
|
when :date
|
|
397
397
|
'date'
|
|
398
398
|
when :binary
|
|
@@ -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
|
@@ -121,6 +121,26 @@ module Arel
|
|
|
121
121
|
)
|
|
122
122
|
end
|
|
123
123
|
|
|
124
|
+
def self.json_true
|
|
125
|
+
res = Arel.grouping(Arel.quoted('true'))
|
|
126
|
+
res.instance_eval {
|
|
127
|
+
def return_type
|
|
128
|
+
:boolean
|
|
129
|
+
end
|
|
130
|
+
}
|
|
131
|
+
res
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def self.json_false
|
|
135
|
+
res = Arel.grouping(Arel.quoted('false'))
|
|
136
|
+
res.instance_eval {
|
|
137
|
+
def return_type
|
|
138
|
+
:boolean
|
|
139
|
+
end
|
|
140
|
+
}
|
|
141
|
+
res
|
|
142
|
+
end
|
|
143
|
+
|
|
124
144
|
# The NULL literal.
|
|
125
145
|
def self.null
|
|
126
146
|
Arel.quoted(nil)
|
|
@@ -256,6 +276,13 @@ end
|
|
|
256
276
|
|
|
257
277
|
class Arel::Table
|
|
258
278
|
alias_method(:old_alias, :alias) rescue nil
|
|
279
|
+
|
|
280
|
+
# activerecord 7.1 removed the alias. We might need to remove our dependency
|
|
281
|
+
# on the alias if it proves problematic.
|
|
282
|
+
if !self.respond_to?(:table_name)
|
|
283
|
+
alias :table_name :name
|
|
284
|
+
end
|
|
285
|
+
|
|
259
286
|
def alias(name = "#{self.name}_2")
|
|
260
287
|
if name.present?
|
|
261
288
|
Arel::Nodes::TableAlias.new(self, name)
|
data/test/arelx_test_helper.rb
CHANGED
|
@@ -501,7 +501,7 @@ module ArelExtensions
|
|
|
501
501
|
#
|
|
502
502
|
# MySQL is happy to consider that times by default are in UTC.
|
|
503
503
|
assert_equal '2014/03/03 13:42:00', t(@lucas, @updated_at.send(method, '%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['paris']}))
|
|
504
|
-
refute_equal '2014/03/03 13:42:00', t(@lucas, @updated_at.send(method, '%Y/%m/%d %H:%M:%S', tz['paris'])) if
|
|
504
|
+
refute_equal '2014/03/03 13:42:00', t(@lucas, @updated_at.send(method, '%Y/%m/%d %H:%M:%S', tz['paris'])) if !%w[mysql postgresql].include?(ENV['DB'])
|
|
505
505
|
|
|
506
506
|
# Winter/Summer time
|
|
507
507
|
assert_equal '2014/08/03 14:42:00', t(@lucas, (@updated_at + 5.months).send(method, '%Y/%m/%d %H:%M:%S', {tz['utc'] => tz['paris']}))
|
|
@@ -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: 2.1.
|
|
4
|
+
version: 2.1.9
|
|
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:
|
|
13
|
+
date: 2024-05-06 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activerecord
|
|
@@ -67,6 +67,8 @@ extra_rdoc_files:
|
|
|
67
67
|
- functions.html
|
|
68
68
|
files:
|
|
69
69
|
- ".codeclimate.yml"
|
|
70
|
+
- ".github/workflows/publish.yml"
|
|
71
|
+
- ".github/workflows/release.yml"
|
|
70
72
|
- ".github/workflows/ruby.yml"
|
|
71
73
|
- ".gitignore"
|
|
72
74
|
- ".rubocop.yml"
|
|
@@ -79,6 +81,9 @@ files:
|
|
|
79
81
|
- TODO
|
|
80
82
|
- appveyor.yml
|
|
81
83
|
- arel_extensions.gemspec
|
|
84
|
+
- bin/build
|
|
85
|
+
- bin/publish
|
|
86
|
+
- dev/compose.yaml
|
|
82
87
|
- functions.html
|
|
83
88
|
- gemfiles/rails3.gemfile
|
|
84
89
|
- gemfiles/rails4_2.gemfile
|
|
@@ -88,6 +93,7 @@ files:
|
|
|
88
93
|
- gemfiles/rails6.gemfile
|
|
89
94
|
- gemfiles/rails6_1.gemfile
|
|
90
95
|
- gemfiles/rails7.gemfile
|
|
96
|
+
- gemfiles/rails7_1.gemfile
|
|
91
97
|
- gemspecs/arel_extensions-v1.gemspec
|
|
92
98
|
- gemspecs/arel_extensions-v2.gemspec
|
|
93
99
|
- generate_gems.sh
|
|
@@ -208,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
208
214
|
- !ruby/object:Gem::Version
|
|
209
215
|
version: '0'
|
|
210
216
|
requirements: []
|
|
211
|
-
rubygems_version: 3.
|
|
217
|
+
rubygems_version: 3.4.19
|
|
212
218
|
signing_key:
|
|
213
219
|
specification_version: 4
|
|
214
220
|
summary: Extending Arel
|