arel_toolkit 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +56 -7
- data/Gemfile.lock +54 -1
- data/Guardfile +19 -12
- data/README.md +56 -2
- data/Rakefile +8 -0
- data/arel_toolkit.gemspec +6 -0
- data/bin/console +1 -0
- data/lib/arel/extensions/assignment.rb +22 -0
- data/lib/arel/extensions/at_time_zone.rb +30 -0
- data/lib/arel/extensions/contained_within_equals.rb +10 -0
- data/lib/arel/extensions/contains.rb +2 -2
- data/lib/arel/extensions/contains_equals.rb +10 -0
- data/lib/arel/extensions/delete_manager.rb +9 -0
- data/lib/arel/extensions/delete_statement.rb +7 -0
- data/lib/arel/extensions/distinct_from.rb +3 -16
- data/lib/arel/extensions/equality.rb +2 -4
- data/lib/arel/extensions/extract_from.rb +32 -0
- data/lib/arel/extensions/insert_manager.rb +5 -0
- data/lib/arel/extensions/insert_statement.rb +10 -3
- data/lib/arel/extensions/json_get_field.rb +10 -0
- data/lib/arel/extensions/json_get_object.rb +10 -0
- data/lib/arel/extensions/json_path_get_field.rb +10 -0
- data/lib/arel/extensions/json_path_get_object.rb +10 -0
- data/lib/arel/extensions/jsonb_all_key_exists.rb +10 -0
- data/lib/arel/extensions/jsonb_any_key_exists.rb +10 -0
- data/lib/arel/extensions/jsonb_key_exists.rb +10 -0
- data/lib/arel/extensions/named_argument.rb +29 -0
- data/lib/arel/extensions/not_distinct_from.rb +3 -16
- data/lib/arel/extensions/not_equal.rb +2 -4
- data/lib/arel/extensions/overlap.rb +1 -1
- data/lib/arel/extensions/overlaps.rb +40 -0
- data/lib/arel/extensions/overlay.rb +44 -0
- data/lib/arel/extensions/position.rb +32 -0
- data/lib/arel/extensions/select_manager.rb +9 -0
- data/lib/arel/extensions/substring.rb +38 -0
- data/lib/arel/extensions/transaction.rb +50 -0
- data/lib/arel/extensions/trim.rb +36 -0
- data/lib/arel/extensions/type_cast.rb +4 -0
- data/lib/arel/{sql_to_arel → extensions}/unbound_column_reference.rb +1 -1
- data/lib/arel/extensions/update_manager.rb +9 -0
- data/lib/arel/extensions/update_statement.rb +8 -0
- data/lib/arel/extensions/variable_set.rb +46 -0
- data/lib/arel/extensions/variable_show.rb +31 -0
- data/lib/arel/extensions.rb +26 -0
- data/lib/arel/middleware/chain.rb +97 -0
- data/lib/arel/middleware/postgresql_adapter.rb +26 -0
- data/lib/arel/middleware/railtie.rb +11 -0
- data/lib/arel/middleware.rb +23 -0
- data/lib/arel/sql_formatter.rb +59 -0
- data/lib/arel/sql_to_arel/error.rb +6 -0
- data/lib/arel/sql_to_arel/pg_query_visitor/frame_options.rb +112 -0
- data/lib/arel/sql_to_arel/pg_query_visitor.rb +271 -52
- data/lib/arel/sql_to_arel/result.rb +17 -0
- data/lib/arel/sql_to_arel.rb +4 -3
- data/lib/arel_toolkit/version.rb +1 -1
- data/lib/arel_toolkit.rb +2 -0
- metadata +120 -4
- data/lib/arel/sql_to_arel/frame_options.rb +0 -110
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12a7a7083cd421854ed6034a0a1cbf83352439d843d7414225267599e9d5a0af
|
4
|
+
data.tar.gz: db2a316896694e49edce2ee52aab4f2283781e45347acaea23fac1fd5dbbf5a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1b77b18061a8332e5e6aa9fe0288fb2526309604f17eb3751d0c363ea1349aaa158fad5106fee32e0a3064cbc21615e1930dd0e59012b92648e75a96cc488190
|
7
|
+
data.tar.gz: 5b04edcfc25b94cb44ac93d4c7472bc7e4d380c20a1d750c41f56e52b754cb0e023b5758e8c35dd2477037e6ff9ca0d2b0aaf5dc7825063fa5b053be7142c142
|
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -19,3 +19,11 @@ script:
|
|
19
19
|
- bundle exec rspec spec
|
20
20
|
after_script:
|
21
21
|
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
22
|
+
deploy:
|
23
|
+
provider: pages
|
24
|
+
skip_cleanup: true
|
25
|
+
github_token: $GITHUB_TOKEN
|
26
|
+
local_dir: ./coverage
|
27
|
+
keep_history: true
|
28
|
+
on:
|
29
|
+
branch: master
|
data/CHANGELOG.md
CHANGED
@@ -1,10 +1,59 @@
|
|
1
|
-
#
|
1
|
+
# Change Log
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## [v0.3.0](https://github.com/mvgijssel/arel_toolkit/tree/v0.3.0) (2019-07-01)
|
4
|
+
[Full Changelog](https://github.com/mvgijssel/arel_toolkit/compare/v0.2.0...v0.3.0)
|
4
5
|
|
5
|
-
|
6
|
+
**Implemented enhancements:**
|
6
7
|
|
7
|
-
-
|
8
|
-
-
|
9
|
-
-
|
10
|
-
-
|
8
|
+
- Implement Functions and Operators from PostgreSQL docs [\#84](https://github.com/mvgijssel/arel_toolkit/issues/84)
|
9
|
+
- Implement more missing operators and visitors [\#82](https://github.com/mvgijssel/arel_toolkit/issues/82)
|
10
|
+
- Improve error message when unable to parse sql to arel [\#71](https://github.com/mvgijssel/arel_toolkit/issues/71)
|
11
|
+
- Publish coverage information to GitHub pages [\#64](https://github.com/mvgijssel/arel_toolkit/issues/64)
|
12
|
+
- Add ActiveRecord comparison testing [\#61](https://github.com/mvgijssel/arel_toolkit/issues/61)
|
13
|
+
- Make Arel::TreeManager equal to other trees [\#59](https://github.com/mvgijssel/arel_toolkit/issues/59)
|
14
|
+
- Add support for Arel.middleware [\#52](https://github.com/mvgijssel/arel_toolkit/issues/52)
|
15
|
+
- Handle multiple tree entries in pg\_query\_visitor\#accept [\#33](https://github.com/mvgijssel/arel_toolkit/issues/33)
|
16
|
+
|
17
|
+
**Fixed bugs:**
|
18
|
+
|
19
|
+
- Fix invalid generated SQL, add missing visitors and extend operators [\#79](https://github.com/mvgijssel/arel_toolkit/issues/79)
|
20
|
+
- Fix handling of equality with Arel::Nodes::Quoted [\#77](https://github.com/mvgijssel/arel_toolkit/issues/77)
|
21
|
+
- Fix default values for Delete- and UpdateStatement [\#75](https://github.com/mvgijssel/arel_toolkit/issues/75)
|
22
|
+
- Unknown operator `` for IN statement [\#73](https://github.com/mvgijssel/arel_toolkit/issues/73)
|
23
|
+
- NameError: undefined local variable or method `number' for \#\<Arel::SqlToArel::PgQueryVisitor:0x000055dfdd14c6f8\> [\#69](https://github.com/mvgijssel/arel_toolkit/issues/69)
|
24
|
+
- Make compatible with postgres\_ext [\#67](https://github.com/mvgijssel/arel_toolkit/issues/67)
|
25
|
+
|
26
|
+
**Closed issues:**
|
27
|
+
|
28
|
+
- File issues for commented out rspec test [\#51](https://github.com/mvgijssel/arel_toolkit/issues/51)
|
29
|
+
|
30
|
+
## [v0.2.0](https://github.com/mvgijssel/arel_toolkit/tree/v0.2.0) (2019-05-30)
|
31
|
+
[Full Changelog](https://github.com/mvgijssel/arel_toolkit/compare/v0.1.0...v0.2.0)
|
32
|
+
|
33
|
+
**Implemented enhancements:**
|
34
|
+
|
35
|
+
- Handle op in pg\_query\_visitor\#visit\_SelectStmt [\#38](https://github.com/mvgijssel/arel_toolkit/issues/38)
|
36
|
+
- Add WITH, OVERRIDING and RETURNING to INSERT [\#28](https://github.com/mvgijssel/arel_toolkit/issues/28)
|
37
|
+
- Return \(Select|Update|Insert|Delete\)Manager instead of \(Select|Update|Insert|Delete\)Statement [\#25](https://github.com/mvgijssel/arel_toolkit/issues/25)
|
38
|
+
- Implement UNION in sql\_to\_arel [\#24](https://github.com/mvgijssel/arel_toolkit/issues/24)
|
39
|
+
- Extract Arel extensions to their own files [\#23](https://github.com/mvgijssel/arel_toolkit/issues/23)
|
40
|
+
- Implement pg\_query\_visitor method for DELETE [\#22](https://github.com/mvgijssel/arel_toolkit/issues/22)
|
41
|
+
- Implement pg\_query\_visitor method for INSERT [\#21](https://github.com/mvgijssel/arel_toolkit/issues/21)
|
42
|
+
- Implement pg\_query\_visitor method for UPDATE [\#20](https://github.com/mvgijssel/arel_toolkit/issues/20)
|
43
|
+
- Implement all the visitor methods in PgQueryVisitor for SELECT statements [\#11](https://github.com/mvgijssel/arel_toolkit/issues/11)
|
44
|
+
- Introduce Guard [\#5](https://github.com/mvgijssel/arel_toolkit/issues/5)
|
45
|
+
|
46
|
+
**Fixed bugs:**
|
47
|
+
|
48
|
+
- Fix CodeClimate coverage [\#8](https://github.com/mvgijssel/arel_toolkit/issues/8)
|
49
|
+
|
50
|
+
**Closed issues:**
|
51
|
+
|
52
|
+
- Create issues for unknown branches in pg\_query\_visitor [\#19](https://github.com/mvgijssel/arel_toolkit/issues/19)
|
53
|
+
- Remove unnecessary to\_arel remains [\#15](https://github.com/mvgijssel/arel_toolkit/issues/15)
|
54
|
+
- Merge to\_arel gem [\#4](https://github.com/mvgijssel/arel_toolkit/issues/4)
|
55
|
+
|
56
|
+
## [v0.1.0](https://github.com/mvgijssel/arel_toolkit/tree/v0.1.0) (2019-05-16)
|
57
|
+
|
58
|
+
|
59
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/Gemfile.lock
CHANGED
@@ -1,24 +1,54 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
arel_toolkit (0.
|
4
|
+
arel_toolkit (0.3.0)
|
5
|
+
activerecord (~> 5.2.0)
|
5
6
|
arel (~> 9.0.0)
|
7
|
+
pg (~> 1.1.4)
|
6
8
|
pg_query (~> 1.1.0)
|
7
9
|
|
8
10
|
GEM
|
9
11
|
remote: https://rubygems.org/
|
10
12
|
specs:
|
13
|
+
activemodel (5.2.3)
|
14
|
+
activesupport (= 5.2.3)
|
15
|
+
activerecord (5.2.3)
|
16
|
+
activemodel (= 5.2.3)
|
17
|
+
activesupport (= 5.2.3)
|
18
|
+
arel (>= 9.0)
|
19
|
+
activesupport (5.2.3)
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
+
i18n (>= 0.7, < 2)
|
22
|
+
minitest (~> 5.1)
|
23
|
+
tzinfo (~> 1.1)
|
24
|
+
addressable (2.6.0)
|
25
|
+
public_suffix (>= 2.0.2, < 4.0)
|
11
26
|
ansi (1.5.0)
|
12
27
|
arel (9.0.0)
|
13
28
|
ast (2.4.0)
|
14
29
|
binding_of_caller (0.8.0)
|
15
30
|
debug_inspector (>= 0.0.1)
|
16
31
|
coderay (1.1.2)
|
32
|
+
concurrent-ruby (1.1.5)
|
33
|
+
database_cleaner (1.7.0)
|
17
34
|
debug_inspector (0.0.3)
|
18
35
|
diff-lcs (1.3)
|
19
36
|
docile (1.3.1)
|
37
|
+
dpl (1.10.11)
|
38
|
+
faraday (0.15.4)
|
39
|
+
multipart-post (>= 1.2, < 3)
|
40
|
+
faraday-http-cache (2.0.0)
|
41
|
+
faraday (~> 0.8)
|
20
42
|
ffi (1.11.1)
|
21
43
|
formatador (0.2.5)
|
44
|
+
github_changelog_generator (1.14.3)
|
45
|
+
activesupport
|
46
|
+
faraday-http-cache
|
47
|
+
multi_json
|
48
|
+
octokit (~> 4.6)
|
49
|
+
rainbow (>= 2.1)
|
50
|
+
rake (>= 10.0)
|
51
|
+
retriable (~> 2.1)
|
22
52
|
guard (2.15.0)
|
23
53
|
formatador (>= 0.2.4)
|
24
54
|
listen (>= 2.7, < 4.0)
|
@@ -33,7 +63,12 @@ GEM
|
|
33
63
|
guard (~> 2.1)
|
34
64
|
guard-compat (~> 1.1)
|
35
65
|
rspec (>= 2.99.0, < 4.0)
|
66
|
+
guard-rubocop (1.3.0)
|
67
|
+
guard (~> 2.0)
|
68
|
+
rubocop (~> 0.20)
|
36
69
|
hirb (0.7.3)
|
70
|
+
i18n (1.6.0)
|
71
|
+
concurrent-ruby (~> 1.0)
|
37
72
|
interception (0.5)
|
38
73
|
jaro_winkler (1.5.2)
|
39
74
|
json (2.2.0)
|
@@ -43,13 +78,19 @@ GEM
|
|
43
78
|
ruby_dep (~> 1.2)
|
44
79
|
lumberjack (1.0.13)
|
45
80
|
method_source (0.9.2)
|
81
|
+
minitest (5.11.3)
|
82
|
+
multi_json (1.13.1)
|
83
|
+
multipart-post (2.1.1)
|
46
84
|
nenv (0.3.0)
|
47
85
|
notiffany (0.1.1)
|
48
86
|
nenv (~> 0.1)
|
49
87
|
shellany (~> 0.0)
|
88
|
+
octokit (4.14.0)
|
89
|
+
sawyer (~> 0.8.0, >= 0.5.3)
|
50
90
|
parallel (1.17.0)
|
51
91
|
parser (2.6.3.0)
|
52
92
|
ast (~> 2.4.0)
|
93
|
+
pg (1.1.4)
|
53
94
|
pg_query (1.1.0)
|
54
95
|
pry (0.12.2)
|
55
96
|
coderay (~> 1.1.0)
|
@@ -65,11 +106,13 @@ GEM
|
|
65
106
|
pry-stack_explorer (0.4.9.3)
|
66
107
|
binding_of_caller (>= 0.7)
|
67
108
|
pry (>= 0.9.11)
|
109
|
+
public_suffix (3.1.1)
|
68
110
|
rainbow (3.0.0)
|
69
111
|
rake (10.5.0)
|
70
112
|
rb-fsevent (0.10.3)
|
71
113
|
rb-inotify (0.10.0)
|
72
114
|
ffi (~> 1.0)
|
115
|
+
retriable (2.1.0)
|
73
116
|
rspec (3.8.0)
|
74
117
|
rspec-core (~> 3.8.0)
|
75
118
|
rspec-expectations (~> 3.8.0)
|
@@ -92,6 +135,9 @@ GEM
|
|
92
135
|
unicode-display_width (>= 1.4.0, < 1.7)
|
93
136
|
ruby-progressbar (1.10.0)
|
94
137
|
ruby_dep (1.5.0)
|
138
|
+
sawyer (0.8.2)
|
139
|
+
addressable (>= 2.3.5)
|
140
|
+
faraday (> 0.8, < 2.0)
|
95
141
|
shellany (0.0.1)
|
96
142
|
simplecov (0.16.1)
|
97
143
|
docile (~> 1.1)
|
@@ -103,6 +149,9 @@ GEM
|
|
103
149
|
simplecov
|
104
150
|
simplecov-html (0.10.2)
|
105
151
|
thor (0.20.3)
|
152
|
+
thread_safe (0.3.6)
|
153
|
+
tzinfo (1.2.5)
|
154
|
+
thread_safe (~> 0.1)
|
106
155
|
unicode-display_width (1.6.0)
|
107
156
|
|
108
157
|
PLATFORMS
|
@@ -111,8 +160,12 @@ PLATFORMS
|
|
111
160
|
DEPENDENCIES
|
112
161
|
arel_toolkit!
|
113
162
|
bundler (~> 2.0)
|
163
|
+
database_cleaner (~> 1.7.0)
|
164
|
+
dpl (~> 1.10.11)
|
165
|
+
github_changelog_generator (~> 1.14.3)
|
114
166
|
guard (~> 2.15)
|
115
167
|
guard-rspec (~> 4.7)
|
168
|
+
guard-rubocop (~> 1.3.0)
|
116
169
|
pry
|
117
170
|
pry-alias
|
118
171
|
pry-nav
|
data/Guardfile
CHANGED
@@ -24,19 +24,26 @@
|
|
24
24
|
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
25
25
|
# * 'just' rspec: 'rspec'
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
group :red_green_refactor, halt_on_fail: true do
|
28
|
+
guard :rspec, cmd: 'bundle exec rspec', failed_mode: :focus do
|
29
|
+
require 'guard/rspec/dsl'
|
30
|
+
dsl = Guard::RSpec::Dsl.new(self)
|
30
31
|
|
31
|
-
|
32
|
+
# Feel free to open issues for suggestions and improvements
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
# RSpec files
|
35
|
+
rspec = dsl.rspec
|
36
|
+
watch(rspec.spec_helper) { rspec.spec_dir }
|
37
|
+
watch(rspec.spec_support) { rspec.spec_dir }
|
38
|
+
watch(rspec.spec_files)
|
38
39
|
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
# Ruby files
|
41
|
+
ruby = dsl.ruby
|
42
|
+
dsl.watch_spec_files_for(ruby.lib_files)
|
43
|
+
end
|
44
|
+
|
45
|
+
guard :rubocop do
|
46
|
+
watch(/.+\.rb$/)
|
47
|
+
watch(%r{(?:.+/)?\.rubocop(?:_todo)?\.yml$}) { |m| File.dirname(m[0]) }
|
48
|
+
end
|
42
49
|
end
|
data/README.md
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
|
10
10
|
- ![](http://ruby-gem-downloads-badge.herokuapp.com/arel_toolkit?type=total)
|
11
11
|
- ![](http://ruby-gem-downloads-badge.herokuapp.com/arel_toolkit?label=downloads-current-version)
|
12
|
+
- [Coverage report](https://mvgijssel.github.io/arel_toolkit/)
|
12
13
|
|
13
14
|
## Installation
|
14
15
|
|
@@ -28,7 +29,7 @@ Or install it yourself as:
|
|
28
29
|
|
29
30
|
## sql_to_arel
|
30
31
|
|
31
|
-
Convert your (PostgreSQL) SQL into Arel.
|
32
|
+
Convert your (PostgreSQL) SQL into an Arel AST.
|
32
33
|
|
33
34
|
```ruby
|
34
35
|
[1] > sql = 'SELECT id FROM users'
|
@@ -41,7 +42,60 @@ Convert your (PostgreSQL) SQL into Arel.
|
|
41
42
|
|
42
43
|
## Extensions
|
43
44
|
|
44
|
-
Adds
|
45
|
+
Adds missing Arel nodes and extends the existing visitors, [lib/arel/extensions](https://github.com/mvgijssel/arel_toolkit/tree/master/lib/arel/extensions) for a full list.
|
46
|
+
|
47
|
+
## Middleware
|
48
|
+
|
49
|
+
The middleware sits between ActiveRecord and the database, which allows you to mutate or log queries before they hit the database. Multiple middleware are supported by passing the results from a finished middleware to the next. User defined context will be passed, which can contains things like the `current_user_id`.
|
50
|
+
|
51
|
+
### Example
|
52
|
+
|
53
|
+
Create an initializer in Rails which loads the Arel::Middleware **after** ActiveRecord:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
ActiveSupport.on_load :active_record do
|
57
|
+
Arel::Middleware::Railtie.insert_postgresql
|
58
|
+
end
|
59
|
+
```
|
60
|
+
|
61
|
+
Create some middleware (can be any Ruby object which responds to `call`):
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
class ReorderMiddleware
|
65
|
+
def self.call(arel, _context)
|
66
|
+
arel.order(Post.arel_table[:id].asc)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class LoggingMiddleware
|
71
|
+
def self.call(arel, context)
|
72
|
+
puts "User executing query: `#{context[:current_user_id]}`"
|
73
|
+
puts "Original SQL: `#{context[:original_sql]}`"
|
74
|
+
puts "Modified SQL: `#{arel.to_sql}`"
|
75
|
+
arel
|
76
|
+
end
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
80
|
+
Run a query with middleware applied
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
[1] > Arel.middleware.apply([ReorderMiddleware, LoggingMiddleware]).context(current_user_id: 1) { Post.all.load }
|
84
|
+
User executing query: `1`
|
85
|
+
Original SQL: `SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC`
|
86
|
+
Modified SQL: `SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC, "posts"."id" ASC`
|
87
|
+
Post Load (4.1ms) SELECT "posts".* FROM "posts" ORDER BY "posts"."id" DESC, "posts"."id" ASC
|
88
|
+
=> []
|
89
|
+
```
|
90
|
+
|
91
|
+
There are more methods available to help with ordering and modifying of the current applied middleware:
|
92
|
+
|
93
|
+
- `Arel.middleware.apply([SomeMiddleware]) { ... }`
|
94
|
+
- `Arel.middleware.only([OnlyMe]) { ... }`
|
95
|
+
- `Arel.middleware.none { ... }`
|
96
|
+
- `Arel.middleware.except(RemoveMe) { ... }`
|
97
|
+
- `Arel.middleware.insert_before(RunBefore, ThisMiddleware) { ... }`
|
98
|
+
- `Arel.middleware.insert_after(RunAfter, ThisMiddleware) { ... }`
|
45
99
|
|
46
100
|
## Development
|
47
101
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
|
+
require 'github_changelog_generator/task'
|
3
4
|
|
4
5
|
RSpec::Core::RakeTask.new(:spec)
|
5
6
|
|
6
7
|
task default: :spec
|
8
|
+
|
9
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
|
10
|
+
config.user = 'mvgijssel'
|
11
|
+
config.project = 'arel_toolkit'
|
12
|
+
config.future_release = "v#{ArelToolkit::VERSION}"
|
13
|
+
config.pulls = false
|
14
|
+
end
|
data/arel_toolkit.gemspec
CHANGED
@@ -25,17 +25,23 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.require_paths = ['lib']
|
26
26
|
|
27
27
|
spec.add_dependency 'arel', '~> 9.0.0'
|
28
|
+
spec.add_dependency 'activerecord', '~> 5.2.0'
|
29
|
+
spec.add_dependency 'pg', '~> 1.1.4'
|
28
30
|
spec.add_dependency 'pg_query', '~> 1.1.0'
|
29
31
|
|
30
32
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
33
|
+
spec.add_development_dependency 'dpl', '~> 1.10.11'
|
34
|
+
spec.add_development_dependency 'github_changelog_generator', '~> 1.14.3'
|
31
35
|
spec.add_development_dependency 'rake', '~> 10.0'
|
32
36
|
spec.add_development_dependency 'rspec', '~> 3.8'
|
37
|
+
spec.add_development_dependency 'database_cleaner', '~> 1.7.0'
|
33
38
|
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
34
39
|
spec.add_development_dependency 'simplecov-console', '~> 0.4.2'
|
35
40
|
|
36
41
|
spec.add_development_dependency 'rubocop', '~> 0.69'
|
37
42
|
spec.add_development_dependency 'guard', '~> 2.15'
|
38
43
|
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
44
|
+
spec.add_development_dependency 'guard-rubocop', '~> 1.3.0'
|
39
45
|
|
40
46
|
spec.add_development_dependency 'pry'
|
41
47
|
spec.add_development_dependency 'pry-nav'
|
data/bin/console
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
module Arel
|
4
|
+
module Visitors
|
5
|
+
class ToSql
|
6
|
+
def visit_Arel_Nodes_Assignment(o, collector)
|
7
|
+
collector = visit o.left, collector
|
8
|
+
collector << ' = '
|
9
|
+
|
10
|
+
case o.right
|
11
|
+
when Arel::Nodes::Node, Arel::Attributes::Attribute
|
12
|
+
visit o.right, collector
|
13
|
+
else
|
14
|
+
collector << quote(o.right).to_s
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# rubocop:enable Naming/MethodName
|
22
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
# https://www.postgresql.org/docs/9.2/functions-datetime.html#FUNCTIONS-DATETIME-ZONECONVERT
|
7
|
+
class AtTimeZone < Arel::Nodes::Unary
|
8
|
+
attr_reader :timezone
|
9
|
+
|
10
|
+
def initialize(expr, timezone)
|
11
|
+
super(expr)
|
12
|
+
|
13
|
+
@timezone = timezone
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Visitors
|
19
|
+
class ToSql
|
20
|
+
def visit_Arel_Nodes_AtTimeZone(o, collector)
|
21
|
+
visit o.expr, collector
|
22
|
+
collector << ' AT TIME ZONE '
|
23
|
+
visit o.timezone, collector
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# rubocop:enable Naming/MethodName
|
30
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module Arel
|
2
2
|
module Nodes
|
3
3
|
# https://www.postgresql.org/docs/9.1/functions-array.html
|
4
|
-
class Contains < InfixOperation
|
4
|
+
class Contains < Arel::Nodes::InfixOperation
|
5
5
|
def initialize(left, right)
|
6
|
-
super('@>', left, right)
|
6
|
+
super(:'@>', left, right)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
@@ -8,6 +8,13 @@ module Arel
|
|
8
8
|
attr_accessor :using
|
9
9
|
attr_accessor :with
|
10
10
|
attr_accessor :returning
|
11
|
+
|
12
|
+
alias_method :old_initialize, :initialize
|
13
|
+
def initialize(relation = nil, wheres = [])
|
14
|
+
old_initialize(relation, wheres)
|
15
|
+
|
16
|
+
@returning = []
|
17
|
+
end
|
11
18
|
end
|
12
19
|
end
|
13
20
|
|
@@ -1,22 +1,9 @@
|
|
1
|
-
# rubocop:disable Naming/MethodName
|
2
|
-
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
-
|
4
1
|
module Arel
|
5
2
|
module Nodes
|
6
|
-
class DistinctFrom < Arel::Nodes::
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
module Visitors
|
11
|
-
class ToSql
|
12
|
-
def visit_Arel_Nodes_DistinctFrom(o, collector)
|
13
|
-
visit o.left, collector
|
14
|
-
collector << ' IS DISTINCT FROM '
|
15
|
-
visit o.right, collector
|
3
|
+
class DistinctFrom < Arel::Nodes::InfixOperation
|
4
|
+
def initialize(left, right)
|
5
|
+
super(:'IS DISTINCT FROM', left, right)
|
16
6
|
end
|
17
7
|
end
|
18
8
|
end
|
19
9
|
end
|
20
|
-
|
21
|
-
# rubocop:enable Naming/MethodName
|
22
|
-
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -6,15 +6,13 @@ module Arel
|
|
6
6
|
class ToSql
|
7
7
|
def visit_Arel_Nodes_Equality(o, collector)
|
8
8
|
right = o.right
|
9
|
-
|
10
9
|
collector = visit o.left, collector
|
11
10
|
|
12
|
-
|
13
|
-
when Arel::Nodes::Unknown, Arel::Nodes::False, Arel::Nodes::True
|
11
|
+
if [Arel::Nodes::Unknown, Arel::Nodes::False, Arel::Nodes::True].include?(right.class)
|
14
12
|
collector << ' IS '
|
15
13
|
visit right, collector
|
16
14
|
|
17
|
-
|
15
|
+
elsif right.nil?
|
18
16
|
collector << ' IS NULL'
|
19
17
|
|
20
18
|
else
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
# https://www.postgresql.org/docs/9.1/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
|
7
|
+
class ExtractFrom < Arel::Nodes::Unary
|
8
|
+
attr_reader :field
|
9
|
+
|
10
|
+
def initialize(expr, field)
|
11
|
+
super(expr)
|
12
|
+
|
13
|
+
@field = field
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Visitors
|
19
|
+
class ToSql
|
20
|
+
def visit_Arel_Nodes_ExtractFrom(o, collector)
|
21
|
+
collector << 'extract('
|
22
|
+
visit o.field, collector
|
23
|
+
collector << ' from '
|
24
|
+
visit o.expr, collector
|
25
|
+
collector << ')'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# rubocop:enable Naming/MethodName
|
32
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -6,9 +6,16 @@ module Arel
|
|
6
6
|
# https://www.postgresql.org/docs/9.5/sql-insert.html
|
7
7
|
Arel::Nodes::InsertStatement.class_eval do
|
8
8
|
attr_accessor :with
|
9
|
-
attr_accessor :
|
9
|
+
attr_accessor :conflict
|
10
10
|
attr_accessor :override
|
11
11
|
attr_accessor :returning
|
12
|
+
|
13
|
+
alias_method :old_initialize, :initialize
|
14
|
+
def initialize
|
15
|
+
old_initialize
|
16
|
+
|
17
|
+
@returning = []
|
18
|
+
end
|
12
19
|
end
|
13
20
|
end
|
14
21
|
|
@@ -32,7 +39,7 @@ module Arel
|
|
32
39
|
end
|
33
40
|
|
34
41
|
case o.override
|
35
|
-
when 0
|
42
|
+
when nil, 0
|
36
43
|
collector << ''
|
37
44
|
when 1
|
38
45
|
collector << ' OVERRIDING USER VALUE'
|
@@ -55,7 +62,7 @@ module Arel
|
|
55
62
|
collector = inject_join o.returning, collector, ', '
|
56
63
|
end
|
57
64
|
|
58
|
-
visit(o.
|
65
|
+
visit(o.conflict, collector) if o.conflict
|
59
66
|
collector
|
60
67
|
end
|
61
68
|
# rubocop:enable Metrics/CyclomaticComplexity
|