arel_extensions 1.2.23 → 1.3.1
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 +86 -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/length.rb +6 -0
- 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/string_functions.rb +10 -2
- data/lib/arel_extensions/version.rb +1 -1
- data/lib/arel_extensions/visitors/mssql.rb +109 -51
- data/lib/arel_extensions/visitors/mysql.rb +15 -2
- data/lib/arel_extensions/visitors/oracle.rb +8 -3
- data/lib/arel_extensions/visitors/postgresql.rb +21 -11
- data/lib/arel_extensions/visitors/sqlite.rb +6 -3
- data/lib/arel_extensions/visitors/to_sql.rb +14 -9
- data/lib/arel_extensions/visitors.rb +9 -1
- data/lib/arel_extensions.rb +66 -12
- data/test/arelx_test_helper.rb +45 -0
- 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 +79 -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: 632b32bb630753413ebde8d2ad0d9b567aab88697c64b5abbbf1f50e53789690
|
4
|
+
data.tar.gz: 7d8c0d52c2c07ff36362dbe00b68c1e3216b3924dbd98fea99e5b643953b217e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54438691157a004658d1ce8f3e4c47e76bdaab4d0f569199f13add0bef389dd91c2cc99807625ef18b9e96cdf570069fa529d55720e9393e8ce3783470e24156
|
7
|
+
data.tar.gz: cfc50270090b43b343444dbecba639b32966b1a45fb5f475338b140e5641c14353007f01cb7228a1870445e808244fa441bdf4fcab7a31fdd2e6e8618bb901bf
|
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,55 @@ t[:birthdate].month.to_sql
|
|
130
130
|
|
131
131
|
t[:birthdate].year.to_sql
|
132
132
|
# => YEAR(my_table.birthdate)
|
133
|
+
```
|
134
|
+
|
135
|
+
### Datetime
|
133
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:
|
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 is:
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
t[:birthdate].format('%Y/%m/%d %H:%M:%S', 'posix/Pacific/Tahiti')
|
159
|
+
# => DATE_FORMAT(CONVERT_TZ(CAST(my_table.birthdate AS datetime), 'UTC', 'posix/Pacific/Tahiti'), '%Y/%m/%d %H:%i:%S') ## MySQL
|
160
|
+
# => TO_CHAR(CAST(my_table.birthdate AS timestamp with time zone) AT TIME ZONE 'posix/Pacific/Tahiti', 'YYYY/MM/DD HH24:MI:SS') ## PostgreSQL
|
161
|
+
# => CONVERT(datetime, my_table.birthdate) AT TIME ZONE 'UTC' AT TIME ZONE N'posix/Pacific/Tahiti' ## SQL Server (& truncated for clarity)
|
162
|
+
# ^^^^^^^^^^^^^^^^^^^^ 🚨 Invalid timezone for SQL Server. Explanation below.
|
163
|
+
```
|
164
|
+
|
165
|
+
This will convert the datetime field to the supplied time zone.
|
166
|
+
|
167
|
+
Warning:
|
168
|
+
|
169
|
+
- ⚠️ Time Zone names are specific to each RDBMS. While `PostgreSQL` and `MySQL`
|
170
|
+
have overlaping names (the ones prefixed with `posix`), you should always
|
171
|
+
read your vendor's documentation. `SQL Server` is a black sheep and has its
|
172
|
+
own conventions.
|
173
|
+
- ⚠️ Daylight saving is managed by the RDBMS vendor. Choose the approptiate time
|
174
|
+
zone name that enforces proper daylight saving conversions.
|
175
|
+
- ☣️ Choosing `GMT+offset` will certainly bypass daylight saving computations.
|
176
|
+
- ☣️ Choosing abbreviate forms like `CET`, which stands for `Central European
|
177
|
+
Time` will behave differently on `PostgreSQL` and `MySQL`. Don't assume
|
178
|
+
uniform behavior, or even a _rational_ one.
|
179
|
+
- ⚠️ SQLite is not supported.
|
180
|
+
- 🚨 Always test against your setup 🚨
|
181
|
+
|
138
182
|
## Unions
|
139
183
|
|
140
184
|
```ruby
|
@@ -596,3 +640,45 @@ User.connection.execute(insert_manager.to_sql)
|
|
596
640
|
</tr>
|
597
641
|
</tbody>
|
598
642
|
</table>
|
643
|
+
|
644
|
+
## Version Compatibility
|
645
|
+
|
646
|
+
<table>
|
647
|
+
<tr><th>Ruby</th> <th>Rails</th> <th>Arel Extensions</th></tr>
|
648
|
+
<tr><td>3.1</td> <td>6.1</td> <td>2</td></tr>
|
649
|
+
<tr><td>3.0</td> <td>6.1</td> <td>2</td></tr>
|
650
|
+
<tr><td>2.7</td> <td>6.1, 6.0</td> <td>2</td></tr>
|
651
|
+
<tr><td>2.5</td> <td>6.1, 6.0</td> <td>2</td></tr>
|
652
|
+
<tr><td>2.5</td> <td>5.2</td> <td>1</td></tr>
|
653
|
+
</table>
|
654
|
+
|
655
|
+
## Development
|
656
|
+
|
657
|
+
Let's say you want to develop/test for `ruby 2.7.5` and `rails 5.2`.
|
658
|
+
|
659
|
+
You will need to fix your ruby version:
|
660
|
+
|
661
|
+
```bash
|
662
|
+
rbenv install 2.7.5
|
663
|
+
rbenv local 2.7.5
|
664
|
+
```
|
665
|
+
|
666
|
+
Fix your gemfiles:
|
667
|
+
|
668
|
+
```bash
|
669
|
+
bundle config set --local gemfile ./gemfiles/rails6.gemfile
|
670
|
+
```
|
671
|
+
|
672
|
+
Install dependencies:
|
673
|
+
```bash
|
674
|
+
bundle install
|
675
|
+
```
|
676
|
+
|
677
|
+
Develop, then test:
|
678
|
+
|
679
|
+
```bash
|
680
|
+
bundle exec rake test:to_sql
|
681
|
+
```
|
682
|
+
|
683
|
+
Refer to the [Version Compatibility](#version-compatibility) section to correctly
|
684
|
+
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: "../"
|