arel_extensions 2.0.20 → 2.1.0
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 +153 -72
- data/README.md +42 -0
- data/arel_extensions.gemspec +1 -1
- data/gemfiles/rails5_2.gemfile +6 -5
- data/gemfiles/rails6.gemfile +6 -6
- data/gemfiles/rails6_1.gemfile +5 -5
- data/gemfiles/rails7.gemfile +30 -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/insert_manager.rb +19 -17
- data/lib/arel_extensions/math.rb +16 -16
- data/lib/arel_extensions/nodes/case.rb +2 -1
- data/lib/arel_extensions/nodes/cast.rb +1 -1
- data/lib/arel_extensions/nodes/function.rb +4 -2
- 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 +1 -1
- data/lib/arel_extensions/visitors/mysql.rb +9 -2
- data/lib/arel_extensions/visitors/oracle.rb +2 -2
- data/lib/arel_extensions/visitors/postgresql.rb +14 -8
- data/lib/arel_extensions/visitors/to_sql.rb +14 -9
- data/lib/arel_extensions/visitors.rb +9 -1
- data/lib/arel_extensions.rb +55 -11
- data/test/real_db_test.rb +5 -1
- data/test/visitors/test_to_sql.rb +18 -11
- data/test/with_ar/all_agnostic_test.rb +14 -4
- 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 +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7a9848d43d40c207414003ca84c7719ad94bf2899b0e480768c623d3fe8d3ce
|
4
|
+
data.tar.gz: 9638df9811fbe0220ba6a1ebd123d2f2fa35794e23c303cd7c29709e2147b2b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ecc111c143ce298c40ce7e595b0b175589ee4e0cd469e180fd69e245219646422435f145ba774d4271878c23d0b1a04e2af840d250c79d159ab2f227d8605b8
|
7
|
+
data.tar.gz: f25c0cf0f3a155c93aad8f295952f701dfb5d4ed5bc2adfef5984884a27700576331624a5d912b95301c8c2ef55cbde650d951676734d4290dcb6372cbec837a
|
data/.github/workflows/ruby.yml
CHANGED
@@ -1,23 +1,63 @@
|
|
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
|
-
|
18
|
-
|
9
|
+
job_build_gem:
|
10
|
+
name: build
|
19
11
|
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby: [3.1, 3.0, 2.7, 2.5]
|
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
|
+
]
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby }}
|
30
|
+
- name: Setup gemspec
|
31
|
+
if: ${{ matrix.rails == '6_1' || matrix.rails == '6' }}
|
32
|
+
run: |
|
33
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
34
|
+
cp ./version_v2.rb lib/arel_extensions/version.rb
|
35
|
+
cp ./gemfiles/rails${{ matrix.rails }}.gemfile ./Gemfile
|
36
|
+
- name: Build source gem
|
37
|
+
run: gem build arel_extensions.gemspec
|
38
|
+
- name: Upload source gem
|
39
|
+
uses: actions/upload-artifact@v2
|
40
|
+
with:
|
41
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
42
|
+
path: "*.gem"
|
20
43
|
|
44
|
+
job_test_linux:
|
45
|
+
name: test linux
|
46
|
+
needs: job_build_gem
|
47
|
+
runs-on: ubuntu-latest
|
48
|
+
strategy:
|
49
|
+
fail-fast: false
|
50
|
+
matrix:
|
51
|
+
ruby: [3.1, 3.0, 2.7, 2.5]
|
52
|
+
rails: [7, 6_1, 6, 5_2]
|
53
|
+
exclude: [
|
54
|
+
{ruby: 3.1, rails: 6 },
|
55
|
+
{ruby: 3.1, rails: 5_2},
|
56
|
+
{ruby: 3.0, rails: 6 },
|
57
|
+
{ruby: 3.0, rails: 5_2},
|
58
|
+
{ruby: 2.7, rails: 5_2},
|
59
|
+
{ruby: 2.5, rails: 7 },
|
60
|
+
]
|
21
61
|
services:
|
22
62
|
postgres:
|
23
63
|
image: postgres:11.6-alpine
|
@@ -28,8 +68,8 @@ jobs:
|
|
28
68
|
# needed because the postgres container does not provide a healthcheck
|
29
69
|
options: >-
|
30
70
|
--health-cmd "pg_isready -d arext_test -U postgres -p 5432"
|
31
|
-
--health-interval 10s
|
32
|
-
--health-timeout 5s
|
71
|
+
--health-interval 10s
|
72
|
+
--health-timeout 5s
|
33
73
|
--health-retries 5
|
34
74
|
mysql:
|
35
75
|
image: mysql:5.7
|
@@ -40,63 +80,104 @@ jobs:
|
|
40
80
|
ports:
|
41
81
|
- 3306:3306
|
42
82
|
options: >-
|
43
|
-
--health-cmd="mysqladmin ping"
|
44
|
-
--health-interval=10s
|
45
|
-
--health-timeout=5s
|
83
|
+
--health-cmd="mysqladmin ping"
|
84
|
+
--health-interval=10s
|
85
|
+
--health-timeout=5s
|
46
86
|
--health-retries=3
|
47
|
-
|
87
|
+
steps:
|
88
|
+
- uses: actions/checkout@v2
|
89
|
+
- name: Set up Ruby
|
90
|
+
uses: ruby/setup-ruby@v1
|
91
|
+
with:
|
92
|
+
ruby-version: ${{ matrix.ruby }}
|
93
|
+
- name: Install FreeTDS
|
94
|
+
run: |
|
95
|
+
sudo apt-get update -q
|
96
|
+
sudo apt-get install -y freetds-dev
|
97
|
+
- name: Install MSSQL 2019
|
98
|
+
uses: potatoqualitee/mssqlsuite@v1
|
99
|
+
with:
|
100
|
+
install: sqlengine, sqlclient, sqlpackage, localdb
|
101
|
+
sa-password: Password12!
|
102
|
+
- name: Update system-wide gems
|
103
|
+
run: gem update --system
|
104
|
+
- name: bundle install
|
105
|
+
run: |
|
106
|
+
bundle config set gemfile ./gemfiles/rails${{ matrix.rails }}.gemfile
|
107
|
+
bundle install
|
108
|
+
- name: Download gem from build job
|
109
|
+
uses: actions/download-artifact@v2
|
110
|
+
with:
|
111
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
112
|
+
- name: Install downloaded gem
|
113
|
+
run: gem install --local *.gem --verbose
|
114
|
+
- name: Run test to_sql
|
115
|
+
run: rake test:to_sql
|
116
|
+
- name: Run test Postgres
|
117
|
+
env:
|
118
|
+
PGHOST: localhost
|
119
|
+
PGUSER: postgres
|
120
|
+
run: rake test:postgresql
|
121
|
+
- name: Run test MySql
|
122
|
+
env:
|
123
|
+
DB_CONNECTION: mysql
|
124
|
+
DB_HOST: 127.0.0.1
|
125
|
+
DB_PORT: 3306
|
126
|
+
DB_DATABASE: arext_test
|
127
|
+
DB_USERNAME: travis
|
128
|
+
run: |
|
129
|
+
mysql --host 127.0.0.1 --port 3306 -uroot -e 'create user travis;'
|
130
|
+
mysql --host 127.0.0.1 --port 3306 -uroot -e 'GRANT ALL PRIVILEGES ON arext_test.* TO travis;'
|
131
|
+
rake test:mysql
|
132
|
+
- name: Run test mssql
|
133
|
+
run: rake test:mssql
|
134
|
+
|
135
|
+
|
136
|
+
job_test_windows:
|
137
|
+
name: test windows
|
138
|
+
needs: job_build_gem
|
139
|
+
runs-on: windows-latest
|
48
140
|
strategy:
|
141
|
+
fail-fast: false
|
49
142
|
matrix:
|
50
|
-
ruby
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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 }}
|
67
|
-
|
143
|
+
ruby: [3.1, 3.0, 2.7, 2.5]
|
144
|
+
rails: [7, 6_1, 6, 5_2]
|
145
|
+
exclude: [
|
146
|
+
{ruby: 3.1, rails: 6 },
|
147
|
+
{ruby: 3.1, rails: 5_2},
|
148
|
+
{ruby: 3.0, rails: 6 },
|
149
|
+
{ruby: 3.0, rails: 5_2},
|
150
|
+
{ruby: 2.7, rails: 5_2},
|
151
|
+
{ruby: 2.5, rails: 7 },
|
152
|
+
]
|
68
153
|
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
|
-
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
|
154
|
+
- uses: actions/checkout@v2
|
155
|
+
- name: Install mssql
|
156
|
+
uses: potatoqualitee/mssqlsuite@v1
|
157
|
+
with:
|
158
|
+
install: sqlengine, sqlclient, sqlpackage, localdb
|
159
|
+
sa-password: Password12!
|
160
|
+
- name: Set up Ruby
|
161
|
+
uses: MSP-Greg/ruby-setup-ruby@win-ucrt-1
|
162
|
+
with:
|
163
|
+
ruby-version: ${{ matrix.ruby }}
|
164
|
+
- name: Install required packages on Windows
|
165
|
+
shell: cmd
|
166
|
+
run: |
|
167
|
+
ridk exec sh -c "pacman --sync --needed --noconfirm ${MINGW_PACKAGE_PREFIX}-gcc"
|
168
|
+
- name: Update system-wide gems
|
169
|
+
run: gem update --system
|
170
|
+
- name: bundle install
|
171
|
+
run: |
|
172
|
+
bundle config set gemfile .\gemfiles\rails${{ matrix.rails }}.gemfile
|
173
|
+
bundle install --verbose
|
174
|
+
- name: Download gem from build job
|
175
|
+
uses: actions/download-artifact@v2
|
176
|
+
with:
|
177
|
+
name: ${{ matrix.ruby }}-${{ matrix.rails }}-gem
|
178
|
+
- name: Install downloaded gem
|
179
|
+
run: gem install --local *.gem --verbose
|
180
|
+
- name: Run test to_sql
|
181
|
+
run: rake test:to_sql
|
182
|
+
- name: Run test mssql
|
183
|
+
run: rake test:mssql
|
data/README.md
CHANGED
@@ -596,3 +596,45 @@ User.connection.execute(insert_manager.to_sql)
|
|
596
596
|
</tr>
|
597
597
|
</tbody>
|
598
598
|
</table>
|
599
|
+
|
600
|
+
## Version Compatibility
|
601
|
+
|
602
|
+
<table>
|
603
|
+
<tr><th>Ruby</th> <th>Rails</th> <th>Arel Extensions</th></tr>
|
604
|
+
<tr><td>3.1</td> <td>6.1</td> <td>2</td></tr>
|
605
|
+
<tr><td>3.0</td> <td>6.1</td> <td>2</td></tr>
|
606
|
+
<tr><td>2.7</td> <td>6.1, 6.0</td> <td>2</td></tr>
|
607
|
+
<tr><td>2.5</td> <td>6.1, 6.0</td> <td>2</td></tr>
|
608
|
+
<tr><td>2.5</td> <td>5.2</td> <td>1</td></tr>
|
609
|
+
</table>
|
610
|
+
|
611
|
+
## Development
|
612
|
+
|
613
|
+
Let's say you want to develop/test for `ruby 2.7.5` and `rails 5.2`.
|
614
|
+
|
615
|
+
You will need to fix your ruby version:
|
616
|
+
|
617
|
+
```bash
|
618
|
+
rbenv install 2.7.5
|
619
|
+
rbenv local 2.7.5
|
620
|
+
```
|
621
|
+
|
622
|
+
Fix your gemfiles:
|
623
|
+
|
624
|
+
```bash
|
625
|
+
bundle config set --local gemfile ./gemfiles/rails6.gemfile
|
626
|
+
```
|
627
|
+
|
628
|
+
Install dependencies:
|
629
|
+
```bash
|
630
|
+
bundle install
|
631
|
+
```
|
632
|
+
|
633
|
+
Develop, then test:
|
634
|
+
|
635
|
+
```bash
|
636
|
+
bundle exec rake test:to_sql
|
637
|
+
```
|
638
|
+
|
639
|
+
Refer to the [Version Compatibility](#version-compatibility) section to correctly
|
640
|
+
set your gemfile.
|
data/arel_extensions.gemspec
CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency('activerecord', '>= 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,16 +4,17 @@ gem 'rails', '~> 5.2.0'
|
|
4
4
|
gem 'arel', '~> 9'
|
5
5
|
|
6
6
|
group :development, :test do
|
7
|
+
gem 'bigdecimal', '1.3.5'
|
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'
|
data/gemfiles/rails6.gemfile
CHANGED
@@ -8,12 +8,12 @@ group :development, :test do
|
|
8
8
|
gem 'activemodel', '~> 6.0.0'
|
9
9
|
gem 'activerecord', '~> 6.0.0'
|
10
10
|
|
11
|
-
gem "sqlite3", '~> 1.4', platforms: [:mri
|
12
|
-
|
13
|
-
|
11
|
+
gem "sqlite3", '~> 1.4', platforms: [:mri]
|
12
|
+
gem "mysql2", '0.5.2', platforms: [:mri]
|
13
|
+
gem "pg",'< 1.0.0', platforms: [:mri]
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
gem "tiny_tds", 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, :mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
19
|
gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
|
@@ -27,4 +27,4 @@ group :development, :test do
|
|
27
27
|
gem "activerecord-jdbcmssql-adapter", platforms: :jruby
|
28
28
|
end
|
29
29
|
|
30
|
-
gemspec path: "../"
|
30
|
+
gemspec path: "../"
|
data/gemfiles/rails6_1.gemfile
CHANGED
@@ -8,12 +8,12 @@ group :development, :test do
|
|
8
8
|
gem 'activemodel', '~> 6.1.0'
|
9
9
|
gem 'activerecord', '~> 6.1.0'
|
10
10
|
|
11
|
-
gem "sqlite3", '~> 1.4', platforms: [:mri
|
12
|
-
gem "mysql2", '0.5.2', platforms: [:mri
|
13
|
-
gem "pg",'~> 1.1', platforms: [:mri
|
11
|
+
gem "sqlite3", '~> 1.4', platforms: [:mri]
|
12
|
+
gem "mysql2", '0.5.2', platforms: [:mri]
|
13
|
+
gem "pg",'~> 1.1', platforms: [:mri]
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
gem "tiny_tds", platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
16
|
+
gem "activerecord-sqlserver-adapter", '~> 6.1.0', platforms: [:mri, :mingw, :x64_mingw, :mswin]
|
17
17
|
|
18
18
|
gem 'ruby-oci8', platforms: [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
19
|
gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
|
@@ -0,0 +1,30 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem 'rails', '~> 7.0.1'
|
4
|
+
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem 'activesupport', '~> 7.0.1'
|
8
|
+
gem 'activemodel', '~> 7.0.1'
|
9
|
+
gem 'activerecord', '~> 7.0.1'
|
10
|
+
|
11
|
+
gem "sqlite3", '~> 1.4', platforms: [:mri, :mswin, :mingw]
|
12
|
+
gem "mysql2", '0.5.2', platforms: [:mri, :mswin, :mingw]
|
13
|
+
gem "pg",'~> 1.1', platforms: [:mri, :mingw]
|
14
|
+
|
15
|
+
#gem "tiny_tds", platforms: [:mri, :mingw] if RUBY_PLATFORM =~ /windows/
|
16
|
+
#gem "activerecord-sqlserver-adapter", platforms: [:mri, :mingw]
|
17
|
+
|
18
|
+
gem 'ruby-oci8', platforms: [:mri, :mswin, :mingw] if ENV.has_key? 'ORACLE_HOME'
|
19
|
+
gem 'activerecord-oracle_enhanced-adapter', '~> 6.0.0' if ENV.has_key? 'ORACLE_HOME'
|
20
|
+
|
21
|
+
# for JRuby
|
22
|
+
gem 'activerecord-jdbc-adapter', platforms: :jruby
|
23
|
+
gem "jdbc-sqlite3", platforms: :jruby
|
24
|
+
gem "activerecord-jdbcsqlite3-adapter", platforms: :jruby
|
25
|
+
gem "activerecord-jdbcmysql-adapter", platforms: :jruby
|
26
|
+
gem "activerecord-jdbcpostgresql-adapter", platforms: :jruby
|
27
|
+
gem "activerecord-jdbcmssql-adapter", platforms: :jruby
|
28
|
+
end
|
29
|
+
|
30
|
+
gemspec path: "../"
|
@@ -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
|
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_dependency('activerecord', '>= 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
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'arel_extensions/aliases'
|
1
2
|
require 'arel_extensions/math'
|
2
3
|
require 'arel_extensions/comparators'
|
3
4
|
require 'arel_extensions/date_duration'
|
@@ -8,6 +9,7 @@ require 'arel_extensions/predications'
|
|
8
9
|
|
9
10
|
module ArelExtensions
|
10
11
|
module Attributes
|
12
|
+
include ArelExtensions::Aliases
|
11
13
|
include ArelExtensions::Math
|
12
14
|
include ArelExtensions::Comparators
|
13
15
|
include ArelExtensions::DateDuration
|
@@ -3,23 +3,25 @@ require 'arel'
|
|
3
3
|
module ArelExtensions
|
4
4
|
module InsertManager
|
5
5
|
def bulk_insert(cols, data)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
6
|
+
raise ArgumentError, "cols must be present" if cols.blank?
|
7
|
+
columns =
|
8
|
+
case cols.first
|
9
|
+
when Array
|
10
|
+
case cols.first.first
|
11
|
+
when Arel::Attributes::Attribute
|
12
|
+
cols
|
13
|
+
when String, Symbol
|
14
|
+
cols.map {|c| [@ast.relation[c.first]] }
|
15
|
+
else
|
16
|
+
raise ArgumentError, "cols has an invalid type: #{cols.first.first.class}"
|
17
|
+
end
|
18
|
+
when String, Symbol
|
19
|
+
cols.map { |c| @ast.relation[c] }
|
20
|
+
else
|
21
|
+
raise ArgumentError, "cols has an invalid type: #{cols.first.class}"
|
22
|
+
end
|
23
|
+
self.values = BulkValues.new(columns, data)
|
24
|
+
@ast.columns = columns
|
23
25
|
end
|
24
26
|
|
25
27
|
class BulkValues < Arel::Nodes::Node
|
data/lib/arel_extensions/math.rb
CHANGED
@@ -22,21 +22,21 @@ module ArelExtensions
|
|
22
22
|
if self.expr.left.is_a?(String) || self.expr.right.is_a?(String)
|
23
23
|
return self.concat(other)
|
24
24
|
else
|
25
|
-
return Arel
|
25
|
+
return Arel.grouping(Arel::Nodes::Addition.new self, other)
|
26
26
|
end
|
27
27
|
when ArelExtensions::Nodes::Function,ArelExtensions::Nodes::Case
|
28
28
|
return case self.return_type
|
29
29
|
when :string, :text
|
30
30
|
self.concat(other)
|
31
31
|
when :integer, :decimal, :float, :number, :int
|
32
|
-
Arel
|
32
|
+
Arel.grouping(Arel::Nodes::Addition.new self, other)
|
33
33
|
when :date, :datetime
|
34
34
|
ArelExtensions::Nodes::DateAdd.new [self, other]
|
35
35
|
else
|
36
36
|
self.concat(other)
|
37
37
|
end
|
38
38
|
when Arel::Nodes::Function
|
39
|
-
Arel
|
39
|
+
Arel.grouping(Arel::Nodes::Addition.new self, other)
|
40
40
|
else
|
41
41
|
begin
|
42
42
|
col = Arel::Table.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s]
|
@@ -44,15 +44,15 @@ module ArelExtensions
|
|
44
44
|
col = nil
|
45
45
|
end
|
46
46
|
if (!col) # if the column doesn't exist in the database
|
47
|
-
Arel
|
47
|
+
Arel.grouping(Arel::Nodes::Addition.new(self, other))
|
48
48
|
else
|
49
49
|
arg = col.type
|
50
50
|
if arg == :integer || (!arg)
|
51
51
|
other = other.to_i if other.is_a?(String)
|
52
|
-
Arel
|
52
|
+
Arel.grouping(Arel::Nodes::Addition.new self, other)
|
53
53
|
elsif arg == :decimal || arg == :float
|
54
54
|
other = Arel.sql(other) if other.is_a?(String) # Arel should accept Float & BigDecimal!
|
55
|
-
Arel
|
55
|
+
Arel.grouping(Arel::Nodes::Addition.new self, other)
|
56
56
|
elsif arg == :datetime || arg == :date
|
57
57
|
ArelExtensions::Nodes::DateAdd.new [self, other]
|
58
58
|
elsif arg == :string || arg == :text
|
@@ -68,23 +68,23 @@ module ArelExtensions
|
|
68
68
|
case self
|
69
69
|
when Arel::Nodes::Grouping
|
70
70
|
if self.expr.left.is_a?(Date) || self.expr.left.is_a?(DateTime)
|
71
|
-
Arel
|
71
|
+
Arel.grouping(ArelExtensions::Nodes::DateSub.new [self, other])
|
72
72
|
else
|
73
|
-
Arel
|
73
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
74
74
|
end
|
75
75
|
when ArelExtensions::Nodes::Function, ArelExtensions::Nodes::Case
|
76
76
|
case self.return_type
|
77
77
|
when :string, :text # ???
|
78
|
-
Arel
|
78
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other)) # ??
|
79
79
|
when :integer, :decimal, :float, :number
|
80
|
-
Arel
|
80
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
81
81
|
when :date, :datetime
|
82
82
|
ArelExtensions::Nodes::DateSub.new [self, other]
|
83
83
|
else
|
84
|
-
Arel
|
84
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
85
85
|
end
|
86
86
|
when Arel::Nodes::Function
|
87
|
-
Arel
|
87
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
88
88
|
else
|
89
89
|
begin
|
90
90
|
col = Arel::Table.engine.connection.schema_cache.columns_hash(self.relation.table_name)[self.name.to_s]
|
@@ -92,7 +92,7 @@ module ArelExtensions
|
|
92
92
|
col = nil
|
93
93
|
end
|
94
94
|
if (!col) # if the column doesn't exist in the database
|
95
|
-
Arel
|
95
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
96
96
|
else
|
97
97
|
arg = col.type
|
98
98
|
if (arg == :date || arg == :datetime)
|
@@ -123,11 +123,11 @@ module ArelExtensions
|
|
123
123
|
else
|
124
124
|
case other
|
125
125
|
when Integer, Float, BigDecimal
|
126
|
-
Arel
|
126
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.sql(other.to_s)))
|
127
127
|
when String
|
128
|
-
Arel
|
128
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, Arel.sql(other)))
|
129
129
|
else
|
130
|
-
Arel
|
130
|
+
Arel.grouping(Arel::Nodes::Subtraction.new(self, other))
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
@@ -34,6 +34,7 @@ module ArelExtensions
|
|
34
34
|
include Arel::Math
|
35
35
|
include Arel::Predications
|
36
36
|
include Arel::OrderPredications
|
37
|
+
include ArelExtensions::Aliases
|
37
38
|
include ArelExtensions::Math
|
38
39
|
include ArelExtensions::Comparators
|
39
40
|
include ArelExtensions::Predications
|
@@ -102,7 +103,7 @@ module ArelExtensions
|
|
102
103
|
alias :== :eql?
|
103
104
|
|
104
105
|
def as other
|
105
|
-
Arel::Nodes::As.new self, Arel
|
106
|
+
Arel::Nodes::As.new self, Arel.sql(other)
|
106
107
|
end
|
107
108
|
end
|
108
109
|
end
|
@@ -52,7 +52,9 @@ module ArelExtensions
|
|
52
52
|
case att
|
53
53
|
when Arel::Attributes::Attribute
|
54
54
|
begin
|
55
|
-
Arel::Table.engine.connection.
|
55
|
+
if Arel::Table.engine.connection.tables.include? att.relation.table_name
|
56
|
+
Arel::Table.engine.connection.schema_cache.columns_hash(att.relation.table_name)[att.name.to_s].type
|
57
|
+
end
|
56
58
|
rescue
|
57
59
|
att
|
58
60
|
end
|
@@ -80,7 +82,7 @@ module ArelExtensions
|
|
80
82
|
when ActiveSupport::Duration
|
81
83
|
Arel.sql(object.to_i)
|
82
84
|
when Array
|
83
|
-
Arel
|
85
|
+
Arel.grouping(object.map{|e| convert_to_node(e)})
|
84
86
|
else
|
85
87
|
raise(ArgumentError, "#{object.class} cannot be converted to CONCAT arg")
|
86
88
|
end
|