arel_extensions 2.0.24 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +358 -71
  3. data/Gemfile +8 -8
  4. data/README.md +107 -0
  5. data/gemfiles/rails5_2.gemfile +8 -7
  6. data/gemfiles/rails6.gemfile +7 -8
  7. data/gemfiles/rails6_1.gemfile +6 -7
  8. data/gemfiles/rails7.gemfile +22 -0
  9. data/lib/arel_extensions/aliases.rb +14 -0
  10. data/lib/arel_extensions/attributes.rb +2 -0
  11. data/lib/arel_extensions/date_duration.rb +2 -2
  12. data/lib/arel_extensions/helpers.rb +48 -0
  13. data/lib/arel_extensions/math.rb +17 -27
  14. data/lib/arel_extensions/nodes/case.rb +5 -10
  15. data/lib/arel_extensions/nodes/date_diff.rb +23 -4
  16. data/lib/arel_extensions/nodes/format.rb +3 -2
  17. data/lib/arel_extensions/nodes/function.rb +1 -7
  18. data/lib/arel_extensions/version.rb +1 -1
  19. data/lib/arel_extensions/visitors/mssql.rb +123 -51
  20. data/lib/arel_extensions/visitors/mysql.rb +23 -2
  21. data/lib/arel_extensions/visitors/oracle.rb +13 -1
  22. data/lib/arel_extensions/visitors/postgresql.rb +23 -5
  23. data/lib/arel_extensions/visitors/sqlite.rb +6 -3
  24. data/lib/arel_extensions/visitors/to_sql.rb +13 -8
  25. data/lib/arel_extensions.rb +27 -7
  26. data/test/arelx_test_helper.rb +45 -1
  27. data/test/database.yml +8 -2
  28. data/test/real_db_test.rb +5 -1
  29. data/test/support/fake_record.rb +1 -1
  30. data/test/visitors/test_to_sql.rb +38 -10
  31. data/test/with_ar/all_agnostic_test.rb +83 -5
  32. data/test/with_ar/insert_agnostic_test.rb +6 -2
  33. data/test/with_ar/test_bulk_sqlite.rb +6 -2
  34. data/test/with_ar/test_math_sqlite.rb +6 -2
  35. data/test/with_ar/test_string_mysql.rb +6 -2
  36. data/test/with_ar/test_string_sqlite.rb +6 -2
  37. data/version_v1.rb +1 -1
  38. data/version_v2.rb +1 -1
  39. metadata +6 -4
  40. data/appveyor.yml +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbeb1b141db51f78567bf26939ecb75832dd1c3e524407bf11a56308d8da6d14
4
- data.tar.gz: 543d1893d29e871ebfa9ccdc8e49179cbedf49cd5ccf6b082113925bedffbc81
3
+ metadata.gz: c069fafddb858e0acc7cee0bf1bc435c2127ccdf6e5d870b8e9caff0d31abdb1
4
+ data.tar.gz: 2d0898c4d35fbe0ac72ccb395ef79ae63f10b662ce6003cea0702d55c27b2729
5
5
  SHA512:
6
- metadata.gz: e4957e64d63412917884f8cc79b42b81643a7e512f4a0e0ef2331672f34cf625b1cec88dbefdf3e3c65d8fca63e2258dc0ff56d8e96964a392c12a89657756c9
7
- data.tar.gz: 2d090ca797080248a3a44521cdae686e721e627c787fa971e340c2b9dc08b91e51992fd47265aad6ccf0bee2d73c8a2e72ad5681fe09844008f5e21577a2d8ce
6
+ metadata.gz: aa4f685f2548b172488d6f3537754c51ad269773a2ff525b7e114e8d4da38bfe41c38cbeee20cb67d7557b46c39c10d218e80181ffa5ebe6be393763981d57d3
7
+ data.tar.gz: 664cf3c829c5df39b3ef8c9913cec516214482e328f01a8c71370aa937abc47194a20b31b8d930a297c322e22025d1af9b1b49384df08ec65860203b8bf27f78
@@ -1,102 +1,389 @@
1
- # This workflow uses actions that are not certified by GitHub.
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
- name: Ruby
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
- test:
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: travis
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-version:
51
- - 3.0.0-preview1
52
- - 2.7
53
- - 2.5
54
- - 2.3
55
- rails-version:
56
- - 6_1
57
- - 6
58
- - 5_2
59
- exclude:
60
- - ruby-version: 2.3
61
- rails-version: 6_1
62
- - ruby-version: 2.3
63
- rails-version: 6
64
- - ruby-version: 3.0.0-preview1
65
- rails-version: 5.2
66
- continue-on-error: ${{ true }}
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
- - uses: actions/checkout@v2
70
- - name: Set up Ruby
71
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
72
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
73
- # uses: ruby/setup-ruby@v1
74
- uses: ruby/setup-ruby@21351ecc0a7c196081abca5dc55b08f085efe09a
75
- with:
76
- ruby-version: ${{ matrix.ruby-version }}
77
- - name: Setup gemspec
78
- if: ${{ matrix.rails-version == '6_1' || matrix.rails-version == '6' }}
79
- run: cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
80
- - name: Install dependencies
81
- run: |
82
- export BUNDLE_GEMFILE=gemfiles/rails${{ matrix.rails-version }}.gemfile
83
- bundle install
84
- - name: Run test to_sql
85
- run: rake test:to_sql
86
- - name: Run test Postgres
87
- env:
88
- PGHOST: localhost
89
- PGUSER: postgres
90
- run: rake test:postgresql
91
- - name: Run test MySql
92
- env:
93
- DB_CONNECTION: mysql
94
- DB_HOST: 127.0.0.1
95
- DB_PORT: 3306
96
- DB_DATABASE: arext_test
97
- DB_USERNAME: travis
98
- run: |
99
- sudo apt-get install -y mysql-client
100
- mysql --host 127.0.0.1 --port 3306 -uroot -e 'create user travis;'
101
- mysql --host 127.0.0.1 --port 3306 -uroot -e 'GRANT ALL PRIVILEGES ON arext_test.* TO travis;'
102
- rake test:mysql
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, :mswin, :x64_mingw, :mingw]
7
- gem "mysql2", '0.4.10', platforms: [:mri, :mswin, :x64_mingw, :mingw]
8
- gem "pg", '< 1', platforms: [:mri, :mingw, :x64_mingw, :mswin]
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.3.0',require: false, platforms: [:mri,:mingw, :x64_mingw, :mswin]
16
- gem "activerecord-sqlserver-adapter", '~> 4.2.0', platforms: [:mri, :mingw, :x64_mingw, :mswin]
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', '~> 4.0'
22
- gem 'activemodel', '~> 4.0'
23
- gem 'activerecord', '~> 4.0'
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.
@@ -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, :mswin, :mingw]
12
- gem "mysql2", '0.4.10', platforms: [:mri, :mswin, :mingw]
13
- gem "pg",'< 1.0.0', platforms: [:mri, :mingw]
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] if RUBY_PLATFORM =~ /windows/
16
- # gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw]
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.0', platforms: :jruby
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-jdbcmssql-adapter", platforms: :jruby
28
+ gem "activerecord-jdbcsqlserver-adapter", '~> 52.0', platforms: :jruby
28
29
  end
29
30
 
30
31
  gemspec path: "../"