arel_extensions 1.2.25 → 1.3.2
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 +358 -71
- data/Gemfile +8 -8
- data/README.md +107 -0
- data/arel_extensions.gemspec +1 -1
- data/gemfiles/rails5_2.gemfile +8 -7
- data/gemfiles/rails6.gemfile +7 -8
- data/gemfiles/rails6_1.gemfile +6 -7
- data/gemfiles/rails7.gemfile +22 -0
- data/gemspecs/arel_extensions-v1.gemspec +1 -1
- data/gemspecs/arel_extensions-v2.gemspec +1 -1
- data/lib/arel_extensions/aliases.rb +14 -0
- data/lib/arel_extensions/attributes.rb +2 -0
- data/lib/arel_extensions/date_duration.rb +2 -2
- data/lib/arel_extensions/helpers.rb +48 -0
- data/lib/arel_extensions/insert_manager.rb +19 -17
- data/lib/arel_extensions/math.rb +22 -32
- data/lib/arel_extensions/nodes/case.rb +5 -6
- data/lib/arel_extensions/nodes/cast.rb +1 -1
- data/lib/arel_extensions/nodes/date_diff.rb +23 -4
- data/lib/arel_extensions/nodes/format.rb +3 -2
- data/lib/arel_extensions/nodes/function.rb +2 -6
- data/lib/arel_extensions/nodes/json.rb +3 -1
- data/lib/arel_extensions/nodes/replace.rb +0 -8
- data/lib/arel_extensions/nodes/union.rb +1 -1
- data/lib/arel_extensions/nodes/union_all.rb +1 -1
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/mssql.rb +123 -51
- data/lib/arel_extensions/visitors/mysql.rb +23 -2
- data/lib/arel_extensions/visitors/oracle.rb +13 -1
- data/lib/arel_extensions/visitors/postgresql.rb +28 -10
- data/lib/arel_extensions/visitors/sqlite.rb +6 -3
- data/lib/arel_extensions/visitors/to_sql.rb +13 -8
- data/lib/arel_extensions/visitors.rb +9 -1
- data/lib/arel_extensions.rb +57 -15
- data/test/arelx_test_helper.rb +45 -1
- data/test/database.yml +8 -2
- data/test/real_db_test.rb +5 -1
- data/test/support/fake_record.rb +1 -1
- data/test/visitors/test_to_sql.rb +39 -11
- data/test/with_ar/all_agnostic_test.rb +83 -6
- data/test/with_ar/insert_agnostic_test.rb +6 -2
- data/test/with_ar/test_bulk_sqlite.rb +6 -2
- data/test/with_ar/test_math_sqlite.rb +6 -2
- data/test/with_ar/test_string_mysql.rb +6 -2
- data/test/with_ar/test_string_sqlite.rb +6 -2
- data/version_v1.rb +1 -1
- data/version_v2.rb +1 -1
- metadata +10 -8
- data/appveyor.yml +0 -44
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a07429d6f459dff77dc3fa56aa258f1fee94ecb7401772ec3ceaea8dc0a8c4d7
|
4
|
+
data.tar.gz: d1600677cf0e63777bd8d8b656f4e17f0fa534e23579cfe3c18044e855a6115b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 752646ca62337cff68c38bcda876d5aa1f7cf6cb8f31906b6d6335237aa1a074daf4891b94b45486d758f1af035d87aac2449951aab683d35f84c123b10c39f8
|
7
|
+
data.tar.gz: d3002160ab13dc1ecbdac0d863a72847a4b3f151cfe12ada6d694b4fb02d70a7e16facbe455d474a5e2ce51ca5686c8abfee26962b91f04023e2fdeb335e22e0
|
data/.github/workflows/ruby.yml
CHANGED
@@ -1,102 +1,389 @@
|
|
1
|
-
|
2
|
-
# They are provided by a third-party and are governed by
|
3
|
-
# separate terms of service, privacy policy, and support
|
4
|
-
# documentation.
|
5
|
-
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
-
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
1
|
+
name: Build and Test
|
7
2
|
|
8
|
-
|
3
|
+
# Ruby + Rails Compatibility Matrix from here:
|
4
|
+
# https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html
|
9
5
|
|
10
|
-
on:
|
11
|
-
push:
|
12
|
-
branches: [ master ]
|
13
|
-
pull_request:
|
14
|
-
branches: [ master ]
|
6
|
+
on: [push, pull_request]
|
15
7
|
|
16
8
|
jobs:
|
17
|
-
|
9
|
+
job_build_gem:
|
10
|
+
name: build
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
15
|
+
rails: [7, 6_1, 6, 5_2]
|
16
|
+
exclude: [
|
17
|
+
{ruby: 3.1, rails: 6 },
|
18
|
+
{ruby: 3.1, rails: 5_2},
|
19
|
+
{ruby: 3.0, rails: 6 },
|
20
|
+
{ruby: 3.0, rails: 5_2},
|
21
|
+
{ruby: 2.7, rails: 5_2},
|
22
|
+
{ruby: 2.5, rails: 7 },
|
23
|
+
{ruby: jruby-9.2, rails: 7 },
|
24
|
+
{ruby: jruby-9.3, rails: 7 },
|
25
|
+
]
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v2
|
28
|
+
- name: Set up Ruby
|
29
|
+
uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
32
|
+
- name: Setup gemspec
|
33
|
+
if: ${{ matrix.rails != '5_2' }}
|
34
|
+
run: |
|
35
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
36
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
37
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
38
|
+
- name: Build source gem
|
39
|
+
run: gem build arel_extensions.gemspec
|
40
|
+
- name: Upload source gem
|
41
|
+
uses: actions/upload-artifact@v2
|
42
|
+
with:
|
43
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
44
|
+
path: "*.gem"
|
18
45
|
|
46
|
+
job_test_to_sql:
|
47
|
+
name: test to_sql
|
48
|
+
needs: job_build_gem
|
19
49
|
runs-on: ubuntu-latest
|
50
|
+
strategy:
|
51
|
+
fail-fast: false
|
52
|
+
matrix:
|
53
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
54
|
+
rails: [7, 6_1, 6, 5_2]
|
55
|
+
exclude: [
|
56
|
+
{ruby: 3.1, rails: 6 },
|
57
|
+
{ruby: 3.1, rails: 5_2},
|
58
|
+
{ruby: 3.0, rails: 6 },
|
59
|
+
{ruby: 3.0, rails: 5_2},
|
60
|
+
{ruby: 2.7, rails: 5_2},
|
61
|
+
{ruby: 2.5, rails: 7 },
|
62
|
+
{ruby: jruby-9.2, rails: 7},
|
63
|
+
{ruby: jruby-9.3, rails: 7},
|
64
|
+
]
|
65
|
+
steps:
|
66
|
+
- uses: actions/checkout@v2
|
67
|
+
- name: Set up Ruby
|
68
|
+
uses: ruby/setup-ruby@v1
|
69
|
+
with:
|
70
|
+
ruby-version: ${{ matrix.ruby }}
|
71
|
+
- name: Install FreeTDS
|
72
|
+
run: |
|
73
|
+
sudo apt-get update -q
|
74
|
+
sudo apt-get install -y freetds-dev
|
75
|
+
- name: Update system-wide gems
|
76
|
+
run: gem update --system
|
77
|
+
- name: Download gem from build job
|
78
|
+
uses: actions/download-artifact@v2
|
79
|
+
with:
|
80
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
81
|
+
- name: Setup Gemfile
|
82
|
+
if: ${{ matrix.rails != '5_2' }}
|
83
|
+
run: |
|
84
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
85
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
86
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
87
|
+
- name: bundle install
|
88
|
+
run: |
|
89
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
90
|
+
bundle install
|
91
|
+
- name: Run test to_sql
|
92
|
+
run: bundle exec rake test:to_sql
|
20
93
|
|
94
|
+
job_test_sqlite:
|
95
|
+
name: test sqlite
|
96
|
+
needs: job_build_gem
|
97
|
+
runs-on: ubuntu-latest
|
98
|
+
strategy:
|
99
|
+
fail-fast: false
|
100
|
+
matrix:
|
101
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
102
|
+
rails: [7, 6_1, 6, 5_2]
|
103
|
+
exclude: [
|
104
|
+
{ruby: 3.1, rails: 6 },
|
105
|
+
{ruby: 3.1, rails: 5_2},
|
106
|
+
{ruby: 3.0, rails: 6 },
|
107
|
+
{ruby: 3.0, rails: 5_2},
|
108
|
+
{ruby: 2.7, rails: 5_2},
|
109
|
+
{ruby: 2.5, rails: 7 },
|
110
|
+
{ruby: jruby-9.2, rails: 7},
|
111
|
+
{ruby: jruby-9.3, rails: 7},
|
112
|
+
]
|
113
|
+
steps:
|
114
|
+
- uses: actions/checkout@v2
|
115
|
+
- name: Set up Ruby
|
116
|
+
uses: ruby/setup-ruby@v1
|
117
|
+
with:
|
118
|
+
ruby-version: ${{ matrix.ruby }}
|
119
|
+
- name: Install FreeTDS
|
120
|
+
run: |
|
121
|
+
sudo apt-get update -q
|
122
|
+
sudo apt-get install -y freetds-dev
|
123
|
+
- name: Update system-wide gems
|
124
|
+
run: gem update --system
|
125
|
+
- name: Download gem from build job
|
126
|
+
uses: actions/download-artifact@v2
|
127
|
+
with:
|
128
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
129
|
+
- name: Setup Gemfile
|
130
|
+
if: ${{ matrix.rails != '5_2' }}
|
131
|
+
run: |
|
132
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
133
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
134
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
135
|
+
- name: bundle install
|
136
|
+
run: |
|
137
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
138
|
+
bundle install
|
139
|
+
- name: Run test sqlite
|
140
|
+
run: bundle exec rake test:sqlite
|
141
|
+
|
142
|
+
job_test_postgres:
|
143
|
+
name: test postgres
|
144
|
+
needs: job_build_gem
|
145
|
+
runs-on: ubuntu-latest
|
146
|
+
strategy:
|
147
|
+
fail-fast: false
|
148
|
+
matrix:
|
149
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
150
|
+
rails: [7, 6_1, 6, 5_2]
|
151
|
+
exclude: [
|
152
|
+
{ruby: 3.1, rails: 6 },
|
153
|
+
{ruby: 3.1, rails: 5_2},
|
154
|
+
{ruby: 3.0, rails: 6 },
|
155
|
+
{ruby: 3.0, rails: 5_2},
|
156
|
+
{ruby: 2.7, rails: 5_2},
|
157
|
+
{ruby: 2.5, rails: 7 },
|
158
|
+
{ruby: jruby-9.2, rails: 7},
|
159
|
+
{ruby: jruby-9.3, rails: 7},
|
160
|
+
]
|
21
161
|
services:
|
22
162
|
postgres:
|
23
163
|
image: postgres:11.6-alpine
|
24
164
|
env:
|
25
165
|
POSTGRES_DB: arext_test
|
166
|
+
POSTGRES_PASSWORD: secret
|
26
167
|
ports:
|
27
168
|
- 5432:5432
|
28
169
|
# needed because the postgres container does not provide a healthcheck
|
29
170
|
options: >-
|
30
171
|
--health-cmd "pg_isready -d arext_test -U postgres -p 5432"
|
31
|
-
--health-interval 10s
|
32
|
-
--health-timeout 5s
|
172
|
+
--health-interval 10s
|
173
|
+
--health-timeout 5s
|
33
174
|
--health-retries 5
|
175
|
+
steps:
|
176
|
+
- uses: actions/checkout@v2
|
177
|
+
- name: Set up Ruby
|
178
|
+
uses: ruby/setup-ruby@v1
|
179
|
+
with:
|
180
|
+
ruby-version: ${{ matrix.ruby }}
|
181
|
+
- name: Install FreeTDS
|
182
|
+
run: |
|
183
|
+
sudo apt-get update -q
|
184
|
+
sudo apt-get install -y freetds-dev
|
185
|
+
- name: Update system-wide gems
|
186
|
+
run: gem update --system
|
187
|
+
- name: Download gem from build job
|
188
|
+
uses: actions/download-artifact@v2
|
189
|
+
with:
|
190
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
191
|
+
- name: Setup Gemfile
|
192
|
+
if: ${{ matrix.rails != '5_2' }}
|
193
|
+
run: |
|
194
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
195
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
196
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
197
|
+
- name: bundle install
|
198
|
+
run: |
|
199
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
200
|
+
bundle install
|
201
|
+
- name: Run test Postgres
|
202
|
+
env:
|
203
|
+
PGHOST: localhost
|
204
|
+
PGUSER: postgres
|
205
|
+
run: bundle exec rake test:postgresql
|
206
|
+
|
207
|
+
job_test_mysql:
|
208
|
+
name: test mysql
|
209
|
+
needs: job_build_gem
|
210
|
+
runs-on: ubuntu-latest
|
211
|
+
strategy:
|
212
|
+
fail-fast: false
|
213
|
+
matrix:
|
214
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
215
|
+
rails: [7, 6_1, 6, 5_2]
|
216
|
+
exclude: [
|
217
|
+
{ruby: 3.1, rails: 6 },
|
218
|
+
{ruby: 3.1, rails: 5_2},
|
219
|
+
{ruby: 3.0, rails: 6 },
|
220
|
+
{ruby: 3.0, rails: 5_2},
|
221
|
+
{ruby: 2.7, rails: 5_2},
|
222
|
+
{ruby: 2.5, rails: 7 },
|
223
|
+
{ruby: jruby-9.2, rails: 7 },
|
224
|
+
{ruby: jruby-9.3, rails: 7 },
|
225
|
+
]
|
226
|
+
services:
|
34
227
|
mysql:
|
35
228
|
image: mysql:5.7
|
36
229
|
env:
|
37
230
|
MYSQL_ALLOW_EMPTY_PASSWORD: true
|
38
|
-
MYSQL_USERNAME:
|
231
|
+
MYSQL_USERNAME: root
|
39
232
|
MYSQL_DATABASE: arext_test
|
40
233
|
ports:
|
41
234
|
- 3306:3306
|
42
235
|
options: >-
|
43
|
-
--health-cmd="mysqladmin ping"
|
44
|
-
--health-interval=10s
|
45
|
-
--health-timeout=5s
|
236
|
+
--health-cmd="mysqladmin ping"
|
237
|
+
--health-interval=10s
|
238
|
+
--health-timeout=5s
|
46
239
|
--health-retries=3
|
47
|
-
|
240
|
+
steps:
|
241
|
+
- uses: actions/checkout@v2
|
242
|
+
- name: Set up Ruby
|
243
|
+
uses: ruby/setup-ruby@v1
|
244
|
+
with:
|
245
|
+
ruby-version: ${{ matrix.ruby }}
|
246
|
+
- name: Install FreeTDS
|
247
|
+
run: |
|
248
|
+
sudo apt-get update -q
|
249
|
+
sudo apt-get install -y freetds-dev
|
250
|
+
- name: Update system-wide gems
|
251
|
+
run: gem update --system
|
252
|
+
- name: Download gem from build job
|
253
|
+
uses: actions/download-artifact@v2
|
254
|
+
with:
|
255
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
256
|
+
- name: Setup Gemfile
|
257
|
+
if: ${{ matrix.rails != '5_2' }}
|
258
|
+
run: |
|
259
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
260
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
261
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
262
|
+
- name: bundle install
|
263
|
+
run: |
|
264
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
265
|
+
bundle install
|
266
|
+
- name: Run test MySql
|
267
|
+
env:
|
268
|
+
DB_CONNECTION: mysql
|
269
|
+
DB_HOST: 127.0.0.1
|
270
|
+
DB_PORT: 3306
|
271
|
+
DB_DATABASE: arext_test
|
272
|
+
DB_USERNAME: root
|
273
|
+
run: bundle exec rake test:mysql
|
274
|
+
|
275
|
+
job_test_mssql:
|
276
|
+
name: test mssql on linux
|
277
|
+
needs: job_build_gem
|
278
|
+
runs-on: ubuntu-latest
|
48
279
|
strategy:
|
280
|
+
fail-fast: false
|
49
281
|
matrix:
|
50
|
-
ruby
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
-
|
65
|
-
|
66
|
-
|
282
|
+
ruby: [3.1, 3.0, 2.7, 2.5, jruby-9.2, jruby-9.3]
|
283
|
+
rails: [7, 6_1, 6, 5_2]
|
284
|
+
exclude: [
|
285
|
+
{ruby: 3.1, rails: 6 },
|
286
|
+
{ruby: 3.1, rails: 5_2 },
|
287
|
+
{ruby: 3.0, rails: 6 },
|
288
|
+
{ruby: 3.0, rails: 5_2 },
|
289
|
+
{ruby: 2.7, rails: 5_2 },
|
290
|
+
{ruby: 2.5, rails: 7 },
|
291
|
+
{ruby: jruby-9.2, rails: 7 },
|
292
|
+
{ruby: jruby-9.2, rails: 6_1 },
|
293
|
+
{ruby: jruby-9.2, rails: 6 },
|
294
|
+
{ruby: jruby-9.3, rails: 7 },
|
295
|
+
{ruby: jruby-9.3, rails: 6_1 },
|
296
|
+
{ruby: jruby-9.3, rails: 6 },
|
297
|
+
]
|
298
|
+
steps:
|
299
|
+
- uses: actions/checkout@v2
|
300
|
+
- name: Set up Ruby
|
301
|
+
uses: ruby/setup-ruby@v1
|
302
|
+
with:
|
303
|
+
ruby-version: ${{ matrix.ruby }}
|
304
|
+
- name: Install FreeTDS
|
305
|
+
run: |
|
306
|
+
sudo apt-get update -q
|
307
|
+
sudo apt-get install -y freetds-dev
|
308
|
+
- name: Install MSSQL 2019
|
309
|
+
uses: potatoqualitee/mssqlsuite@v1
|
310
|
+
with:
|
311
|
+
install: sqlengine, sqlclient, sqlpackage, localdb
|
312
|
+
sa-password: Password12!
|
313
|
+
- name: Update system-wide gems
|
314
|
+
run: gem update --system
|
315
|
+
- name: Download gem from build job
|
316
|
+
uses: actions/download-artifact@v2
|
317
|
+
with:
|
318
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
319
|
+
- name: Setup Gemfile
|
320
|
+
if: ${{ matrix.rails != '5_2' }}
|
321
|
+
run: |
|
322
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
323
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
324
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
325
|
+
- name: bundle install
|
326
|
+
run: |
|
327
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
328
|
+
bundle install
|
329
|
+
- name: Run test mssql
|
330
|
+
run: bundle exec rake test:mssql
|
67
331
|
|
332
|
+
job_test_windows:
|
333
|
+
name: test mssql on windows
|
334
|
+
needs: job_build_gem
|
335
|
+
runs-on: windows-latest
|
336
|
+
strategy:
|
337
|
+
fail-fast: false
|
338
|
+
matrix:
|
339
|
+
ruby: [3.1, 3.0, 2.7, 2.5]
|
340
|
+
rails: [7, 6_1, 6, 5_2]
|
341
|
+
exclude: [
|
342
|
+
{ruby: 3.1, rails: 6 },
|
343
|
+
{ruby: 3.1, rails: 5_2 },
|
344
|
+
{ruby: 3.0, rails: 6 },
|
345
|
+
{ruby: 3.0, rails: 5_2 },
|
346
|
+
{ruby: 2.7, rails: 5_2 },
|
347
|
+
{ruby: 2.5, rails: 7 },
|
348
|
+
{ruby: jruby-9.2, rails: 7 },
|
349
|
+
{ruby: jruby-9.2, rails: 6_1 },
|
350
|
+
{ruby: jruby-9.2, rails: 6 },
|
351
|
+
{ruby: jruby-9.3, rails: 7 },
|
352
|
+
{ruby: jruby-9.3, rails: 6_1 },
|
353
|
+
{ruby: jruby-9.3, rails: 6 },
|
354
|
+
]
|
68
355
|
steps:
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
rake test:
|
356
|
+
- uses: actions/checkout@v2
|
357
|
+
- name: Install mssql
|
358
|
+
uses: potatoqualitee/mssqlsuite@v1
|
359
|
+
with:
|
360
|
+
install: sqlengine, sqlclient, sqlpackage, localdb
|
361
|
+
sa-password: Password12!
|
362
|
+
- name: Set up Ruby
|
363
|
+
uses: MSP-Greg/ruby-setup-ruby@win-ucrt-1
|
364
|
+
with:
|
365
|
+
ruby-version: ${{ matrix.ruby }}
|
366
|
+
- name: Install required packages on Windows
|
367
|
+
shell: cmd
|
368
|
+
run: |
|
369
|
+
ridk exec sh -c "pacman --sync --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc"
|
370
|
+
- name: Update system-wide gems
|
371
|
+
run: gem update --system
|
372
|
+
- name: Setup Gemfile
|
373
|
+
if: ${{ matrix.rails != '5_2' }}
|
374
|
+
run: |
|
375
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
376
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
377
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
378
|
+
- name: bundle install
|
379
|
+
run: |
|
380
|
+
bundle config set gemfile .\gemfiles\rails${{ matrix.rails }}.gemfile
|
381
|
+
bundle install --verbose
|
382
|
+
- name: Download gem from build job
|
383
|
+
uses: actions/download-artifact@v2
|
384
|
+
with:
|
385
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
386
|
+
- name: Install downloaded gem
|
387
|
+
run: gem install --local *.gem --verbose
|
388
|
+
- name: Run test mssql
|
389
|
+
run: bundle exec rake test:mssql
|
data/Gemfile
CHANGED
@@ -3,22 +3,22 @@ source "https://rubygems.org"
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
group :development, :test do
|
6
|
-
gem "sqlite3", '<= 1.3.13', platforms: [:mri
|
7
|
-
gem "mysql2", '0.4.10', platforms: [:mri
|
8
|
-
gem "pg", '< 1', platforms: [:mri
|
6
|
+
gem "sqlite3", '<= 1.3.13', platforms: [:mri]
|
7
|
+
gem "mysql2", '0.4.10', platforms: [:mri]
|
8
|
+
gem "pg", '< 1', platforms: [:mri]
|
9
9
|
|
10
10
|
gem "jdbc-sqlite3", platforms: :jruby
|
11
11
|
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
12
12
|
gem "activerecord-jdbcmysql-adapter", platforms: :jruby
|
13
13
|
gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
|
14
14
|
|
15
|
-
gem "tiny_tds", '~> 1
|
16
|
-
gem "activerecord-sqlserver-adapter", '~>
|
15
|
+
gem "tiny_tds", '~> 2.1', require: false, platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
16
|
+
gem "activerecord-sqlserver-adapter", '~> 6.0', platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
17
17
|
|
18
18
|
gem 'ruby-oci8', platforms: [:mri, :mswin, :x64_mingw, :mingw]
|
19
19
|
gem 'activerecord-oracle_enhanced-adapter', '~> 1.6.0'
|
20
20
|
|
21
|
-
gem 'activesupport', '~>
|
22
|
-
gem 'activemodel', '~>
|
23
|
-
gem 'activerecord', '~>
|
21
|
+
gem 'activesupport', '~> 6.0'
|
22
|
+
gem 'activemodel', '~> 6.0'
|
23
|
+
gem 'activerecord', '~> 6.0'
|
24
24
|
end
|
data/README.md
CHANGED
@@ -130,11 +130,76 @@ t[:birthdate].month.to_sql
|
|
130
130
|
|
131
131
|
t[:birthdate].year.to_sql
|
132
132
|
# => YEAR(my_table.birthdate)
|
133
|
+
```
|
134
|
+
|
135
|
+
### Datetime
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
# datetime difference
|
139
|
+
t[:birthdate] - Time.utc(2014, 3, 3, 12, 41, 18)
|
140
|
+
|
141
|
+
# comparison
|
142
|
+
t[:birthdate] >= '2014-03-03 10:10:10'
|
143
|
+
```
|
144
|
+
|
145
|
+
### Format and Time Zone Conversion
|
146
|
+
|
147
|
+
`format` has two forms:
|
133
148
|
|
149
|
+
```ruby
|
134
150
|
t[:birthdate].format('%Y-%m-%d').to_sql
|
135
151
|
# => DATE_FORMAT(my_table.birthdate, '%Y-%m-%d')
|
136
152
|
```
|
137
153
|
|
154
|
+
Which formats the datetime without any time zone conversion.
|
155
|
+
The second form accepts 2 kinds of values:
|
156
|
+
|
157
|
+
1. String:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
t[:birthdate].format('%Y/%m/%d %H:%M:%S', 'posix/Pacific/Tahiti')
|
161
|
+
# => DATE_FORMAT(CONVERT_TZ(CAST(my_table.birthdate AS datetime), 'UTC', 'posix/Pacific/Tahiti'), '%Y/%m/%d %H:%i:%S') ## MySQL
|
162
|
+
# => TO_CHAR(CAST(my_table.birthdate AS timestamp with time zone) AT TIME ZONE 'posix/Pacific/Tahiti', 'YYYY/MM/DD HH24:MI:SS') ## PostgreSQL
|
163
|
+
# => CONVERT(datetime, my_table.birthdate) AT TIME ZONE 'UTC' AT TIME ZONE N'posix/Pacific/Tahiti' ## SQL Server (& truncated for clarity)
|
164
|
+
# ^^^^^^^^^^^^^^^^^^^^ 🚨 Invalid timezone for SQL Server. Explanation below.
|
165
|
+
```
|
166
|
+
|
167
|
+
which will convert the datetime field to the supplied time zone. This generally
|
168
|
+
means that you're letting the RDBMS decide or infer what is the timezone of the
|
169
|
+
column before conversion to the supplied timezone.
|
170
|
+
|
171
|
+
1. Hash of the form `{ src_time_zone => dst_time_zone }`:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
t[:birthdate].format('%Y/%m/%d %H:%M:%S', { 'posix/Europe/Paris' => 'posix/Pacific/Tahiti' })
|
175
|
+
```
|
176
|
+
|
177
|
+
which will explicitly indicate the original timestamp that should be considered
|
178
|
+
by the RDBMS.
|
179
|
+
|
180
|
+
Warning:
|
181
|
+
|
182
|
+
- ⚠️ Time Zone names are specific to each RDBMS. While `PostgreSQL` and `MySQL`
|
183
|
+
have overlaping names (the ones prefixed with `posix`), you should always
|
184
|
+
read your vendor's documentation. `SQL Server` is a black sheep and has its
|
185
|
+
own conventions.
|
186
|
+
- ⚠️ Daylight saving is managed by the RDBMS vendor. Choose the approptiate time
|
187
|
+
zone name that enforces proper daylight saving conversions.
|
188
|
+
- ☣️ Choosing `GMT+offset` will certainly bypass daylight saving computations.
|
189
|
+
- ☣️ Choosing abbreviate forms like `CET`, which stands for `Central European
|
190
|
+
Time` will behave differently on `PostgreSQL` and `MySQL`. Don't assume
|
191
|
+
uniform behavior, or even a _rational_ one.
|
192
|
+
- ⚠️ Pay attention to the type of the `datetime` column you're working with. For
|
193
|
+
example, in Postgres, a `datetime` can be one of the following types:
|
194
|
+
1. `timestamp with time zone`
|
195
|
+
2. `timestamp without time zone`
|
196
|
+
In the first case, you don't need to supply a conversion hash because postgres
|
197
|
+
knows how to convert it to the desired time zone. However, if you do the same
|
198
|
+
for the second case, you might get surprises, especially if your Postgres
|
199
|
+
installation's default timezone is not `UTC`.
|
200
|
+
- ⚠️ SQLite is not supported.
|
201
|
+
- 🚨 Always test against your setup 🚨
|
202
|
+
|
138
203
|
## Unions
|
139
204
|
|
140
205
|
```ruby
|
@@ -596,3 +661,45 @@ User.connection.execute(insert_manager.to_sql)
|
|
596
661
|
</tr>
|
597
662
|
</tbody>
|
598
663
|
</table>
|
664
|
+
|
665
|
+
## Version Compatibility
|
666
|
+
|
667
|
+
<table>
|
668
|
+
<tr><th>Ruby</th> <th>Rails</th> <th>Arel Extensions</th></tr>
|
669
|
+
<tr><td>3.1</td> <td>6.1</td> <td>2</td></tr>
|
670
|
+
<tr><td>3.0</td> <td>6.1</td> <td>2</td></tr>
|
671
|
+
<tr><td>2.7</td> <td>6.1, 6.0</td> <td>2</td></tr>
|
672
|
+
<tr><td>2.5</td> <td>6.1, 6.0</td> <td>2</td></tr>
|
673
|
+
<tr><td>2.5</td> <td>5.2</td> <td>1</td></tr>
|
674
|
+
</table>
|
675
|
+
|
676
|
+
## Development
|
677
|
+
|
678
|
+
Let's say you want to develop/test for `ruby 2.7.5` and `rails 5.2`.
|
679
|
+
|
680
|
+
You will need to fix your ruby version:
|
681
|
+
|
682
|
+
```bash
|
683
|
+
rbenv install 2.7.5
|
684
|
+
rbenv local 2.7.5
|
685
|
+
```
|
686
|
+
|
687
|
+
Fix your gemfiles:
|
688
|
+
|
689
|
+
```bash
|
690
|
+
bundle config set --local gemfile ./gemfiles/rails6.gemfile
|
691
|
+
```
|
692
|
+
|
693
|
+
Install dependencies:
|
694
|
+
```bash
|
695
|
+
bundle install
|
696
|
+
```
|
697
|
+
|
698
|
+
Develop, then test:
|
699
|
+
|
700
|
+
```bash
|
701
|
+
bundle exec rake test:to_sql
|
702
|
+
```
|
703
|
+
|
704
|
+
Refer to the [Version Compatibility](#version-compatibility) section to correctly
|
705
|
+
set your gemfile.
|
data/arel_extensions.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency('arel', '>= 6.0')
|
24
24
|
|
25
25
|
s.add_development_dependency('minitest', '~> 5.9')
|
26
|
-
s.add_development_dependency('rdoc', '
|
26
|
+
s.add_development_dependency('rdoc', '>= 6.3.1')
|
27
27
|
s.add_development_dependency('rake', '~> 12.3.3')
|
28
28
|
end
|
data/gemfiles/rails5_2.gemfile
CHANGED
@@ -4,27 +4,28 @@ gem 'rails', '~> 5.2.0'
|
|
4
4
|
gem 'arel', '~> 9'
|
5
5
|
|
6
6
|
group :development, :test do
|
7
|
+
gem 'bigdecimal', '1.3.5', :platforms => [:mri, :mingw, :x64_mingw, :mswin]
|
7
8
|
gem 'activesupport', '~> 5.2.0'
|
8
9
|
gem 'activemodel', '~> 5.2.0'
|
9
10
|
gem 'activerecord', '~> 5.2.0'
|
10
11
|
|
11
|
-
gem "sqlite3", '<= 1.3.13', platforms: [:mri
|
12
|
-
gem "mysql2", '0.4.10', platforms: [:mri
|
13
|
-
gem "pg",'< 1.0.0', platforms: [:mri
|
12
|
+
gem "sqlite3", '<= 1.3.13', platforms: [:mri]
|
13
|
+
gem "mysql2", '0.4.10', platforms: [:mri]
|
14
|
+
gem "pg",'< 1.0.0', platforms: [:mri]
|
14
15
|
|
15
|
-
gem "tiny_tds", platforms: [:mri, :mingw
|
16
|
-
|
16
|
+
gem "tiny_tds", platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
17
|
+
gem "activerecord-sqlserver-adapter", '~> 5.2', :platforms => [:mri, :mingw, :x64_mingw, :mswin]
|
17
18
|
|
18
19
|
gem 'ruby-oci8', platforms: [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
20
|
gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0' if ENV.has_key? 'ORACLE_HOME'
|
20
21
|
|
21
22
|
# for JRuby
|
22
|
-
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v52.
|
23
|
+
gem 'activerecord-jdbc-adapter', github: 'jruby/activerecord-jdbc-adapter', tag: 'v52.7', platforms: :jruby
|
23
24
|
gem "jdbc-sqlite3", platforms: :jruby
|
24
25
|
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
25
26
|
gem "activerecord-jdbcmysql-adapter", platforms: :jruby
|
26
27
|
gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
|
27
|
-
gem "activerecord-
|
28
|
+
gem "activerecord-jdbcsqlserver-adapter", '~> 52.0', platforms: :jruby
|
28
29
|
end
|
29
30
|
|
30
31
|
gemspec path: "../"
|