arel_extensions 1.2.18 → 1.3.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 +183 -0
- data/README.md +42 -0
- data/arel_extensions.gemspec +3 -3
- data/gemfiles/rails5_2.gemfile +6 -5
- data/gemfiles/rails6.gemfile +6 -6
- data/gemfiles/rails6_1.gemfile +30 -0
- data/gemfiles/rails7.gemfile +30 -0
- data/gemspecs/arel_extensions-v1.gemspec +28 -0
- data/{gemspec_v2 → gemspecs}/arel_extensions-v2.gemspec +1 -1
- data/generate_gems.sh +4 -3
- 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/math_functions.rb +7 -3
- data/lib/arel_extensions/nodes/case.rb +2 -1
- data/lib/arel_extensions/nodes/cast.rb +1 -1
- data/lib/arel_extensions/nodes/concat.rb +1 -1
- data/lib/arel_extensions/nodes/function.rb +9 -3
- 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/std.rb +4 -4
- 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/oracle12.rb +0 -12
- data/lib/arel_extensions/visitors/postgresql.rb +14 -8
- data/lib/arel_extensions/visitors/to_sql.rb +26 -9
- data/lib/arel_extensions/visitors.rb +9 -1
- data/lib/arel_extensions.rb +64 -14
- data/test/database.yml +2 -0
- 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 +20 -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 +14 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95117294eff3a479d73c986f12c5fda0e0c97c40a90622cdf9918e379bfd62d4
|
4
|
+
data.tar.gz: 3b0284695e759e58a9176ae2a594d8ae6f46920d214d4084237d3c84717f58fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0804118ac474e36d33e55198948e349d5566622399a98fcf8a777ed8b8afd77ac47ddbaea9a22cb25a30703e55044ae5ebad6e4bd9a6f6d9b1a2e433fecb9917'
|
7
|
+
data.tar.gz: 570567960b3b32052b5fcd890f3d89404c0ec8c07f8f5a55856f31305ae9e10a22ab6cc0f3648d64227bf210f809bcc5a2864f756ca6b75e684f0ddb31e261e5
|
@@ -0,0 +1,183 @@
|
|
1
|
+
name: Build and Test
|
2
|
+
|
3
|
+
# Ruby + Rails Compatibility Matrix from here:
|
4
|
+
# https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html
|
5
|
+
|
6
|
+
on: [push, pull_request]
|
7
|
+
|
8
|
+
jobs:
|
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]
|
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"
|
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
|
+
]
|
61
|
+
services:
|
62
|
+
postgres:
|
63
|
+
image: postgres:11.6-alpine
|
64
|
+
env:
|
65
|
+
POSTGRES_DB: arext_test
|
66
|
+
ports:
|
67
|
+
- 5432:5432
|
68
|
+
# needed because the postgres container does not provide a healthcheck
|
69
|
+
options: >-
|
70
|
+
--health-cmd "pg_isready -d arext_test -U postgres -p 5432"
|
71
|
+
--health-interval 10s
|
72
|
+
--health-timeout 5s
|
73
|
+
--health-retries 5
|
74
|
+
mysql:
|
75
|
+
image: mysql:5.7
|
76
|
+
env:
|
77
|
+
MYSQL_ALLOW_EMPTY_PASSWORD: true
|
78
|
+
MYSQL_USERNAME: travis
|
79
|
+
MYSQL_DATABASE: arext_test
|
80
|
+
ports:
|
81
|
+
- 3306:3306
|
82
|
+
options: >-
|
83
|
+
--health-cmd="mysqladmin ping"
|
84
|
+
--health-interval=10s
|
85
|
+
--health-timeout=5s
|
86
|
+
--health-retries=3
|
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
|
140
|
+
strategy:
|
141
|
+
fail-fast: false
|
142
|
+
matrix:
|
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
|
+
]
|
153
|
+
steps:
|
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
@@ -20,9 +20,9 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
21
|
s.require_paths = ["lib"]
|
22
22
|
|
23
|
-
s.add_dependency('
|
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
|
-
end
|
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
|
-
gem "tiny_tds", platforms: [:mri, :mingw
|
16
|
-
gem "activerecord-sqlserver-adapter", platforms: [:mri, :mingw]
|
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: "../"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
gem 'rails', '~> 6.1.0'
|
4
|
+
|
5
|
+
|
6
|
+
group :development, :test do
|
7
|
+
gem 'activesupport', '~> 6.1.0'
|
8
|
+
gem 'activemodel', '~> 6.1.0'
|
9
|
+
gem 'activerecord', '~> 6.1.0'
|
10
|
+
|
11
|
+
gem "sqlite3", '~> 1.4', platforms: [:mri]
|
12
|
+
gem "mysql2", '0.5.2', platforms: [:mri]
|
13
|
+
gem "pg",'~> 1.1', platforms: [:mri]
|
14
|
+
|
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
|
+
|
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: "../"
|
@@ -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: "../"
|
@@ -0,0 +1,28 @@
|
|
1
|
+
$:.push File.expand_path("../lib", __FILE__)
|
2
|
+
require "arel_extensions/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "arel_extensions"
|
6
|
+
s.version = ArelExtensions::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Yann Azoury", "Félix Bellanger", "Julien Delporte"]
|
9
|
+
s.email = ["yann.azoury@faveod.com", "felix.bellanger@faveod.com", "julien.delporte@faveod.com"]
|
10
|
+
s.homepage = "https://github.com/Faveod/arel-extensions"
|
11
|
+
s.description = "Adds new features to Arel"
|
12
|
+
s.summary = "Extending Arel"
|
13
|
+
s.license = 'MIT'
|
14
|
+
|
15
|
+
s.rdoc_options = ["--main", "README.md"]
|
16
|
+
s.extra_rdoc_files = ["MIT-LICENSE.txt", "README.md", 'functions.html']
|
17
|
+
|
18
|
+
# Manifest
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
|
23
|
+
s.add_dependency('arel', '>= 6.0')
|
24
|
+
|
25
|
+
s.add_development_dependency('minitest', '~> 5.9')
|
26
|
+
s.add_development_dependency('rdoc', '>= 6.3.1')
|
27
|
+
s.add_development_dependency('rake', '~> 12.3.3')
|
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
|
data/generate_gems.sh
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
|
2
|
-
gem uninstall arel_extensions
|
2
|
+
#gem uninstall arel_extensions
|
3
3
|
|
4
4
|
# VERSION ~> 1
|
5
5
|
cp ./version_v1.rb lib/arel_extensions/version.rb
|
6
|
+
cp ./gemspecs/arel_extensions-v1.gemspec ./arel_extensions.gemspec
|
6
7
|
gem build ./arel_extensions.gemspec
|
7
8
|
|
8
9
|
# VERSION ~> 2
|
9
10
|
cp ./version_v2.rb lib/arel_extensions/version.rb
|
10
11
|
mv ./arel_extensions.gemspec ./arel_extensions.gemspec.bck
|
11
|
-
cp ./
|
12
|
+
cp ./gemspecs/arel_extensions-v2.gemspec ./arel_extensions.gemspec
|
12
13
|
gem build ./arel_extensions.gemspec
|
13
14
|
cp ./version_v1.rb lib/arel_extensions/version.rb
|
14
|
-
cp ./arel_extensions.gemspec
|
15
|
+
cp ./gemspecs/arel_extensions-v1.gemspec ./arel_extensions.gemspec
|
@@ -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
|
@@ -63,15 +63,19 @@ module ArelExtensions
|
|
63
63
|
|
64
64
|
# Aggregate Functions
|
65
65
|
def std opts = {unbiased: true}
|
66
|
-
ArelExtensions::Nodes::Std.new self, opts
|
66
|
+
ArelExtensions::Nodes::Std.new self, **opts
|
67
67
|
end
|
68
68
|
|
69
69
|
def variance opts = {unbiased: true}
|
70
|
-
ArelExtensions::Nodes::Variance.new self, opts
|
70
|
+
ArelExtensions::Nodes::Variance.new self, **opts
|
71
71
|
end
|
72
72
|
|
73
73
|
def sum opts = {unbiased: true}
|
74
|
-
|
74
|
+
if Gem::Version.new(Arel::VERSION) >= Gem::Version.new("9.0.0")
|
75
|
+
Arel::Nodes::Sum.new [self]
|
76
|
+
else
|
77
|
+
ArelExtensions::Nodes::Sum.new self, **opts
|
78
|
+
end
|
75
79
|
end
|
76
80
|
|
77
81
|
# function that can be invoked to produce random numbers between 0 and 1
|
@@ -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
|