Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fa7bd9f

Browse files
committedJan 8, 2025·
Upgrade to PgQuery 5.1.0
1 parent faee1ec commit fa7bd9f

9 files changed

+51
-30
lines changed
 

‎.rubocop.yml

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ AllCops:
66
- 'tmp/**/*'
77
SuggestExtensions: false
88

9+
TargetRubyVersion: 3.0
10+
911
Bundler/OrderedGems:
1012
Enabled: false
1113

‎.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.0.5
1+
3.2.5

‎Gemfile.lock

+16-11
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ PATH
33
specs:
44
arel_toolkit (0.5.0)
55
activerecord (>= 6.1, < 7)
6-
pg (>= 1.1.4)
7-
pg_query (~> 2.2)
6+
pg (>= 1.5.9)
7+
pg_query (~> 5.1)
88

99
GEM
1010
remote: https://rubygems.org/
@@ -51,6 +51,7 @@ GEM
5151
async
5252
async-pool (0.3.12)
5353
async (>= 1.25)
54+
bigdecimal (3.1.9)
5455
binding_of_caller (1.0.0)
5556
debug_inspector (>= 0.0.1)
5657
coderay (1.1.3)
@@ -80,7 +81,9 @@ GEM
8081
octokit (~> 4.6)
8182
rainbow (>= 2.2.1)
8283
rake (>= 10.0)
83-
google-protobuf (3.21.12)
84+
google-protobuf (4.29.2)
85+
bigdecimal
86+
rake (>= 13)
8487
guard (2.18.0)
8588
formatador (>= 0.2.4)
8689
listen (>= 2.7, < 4.0)
@@ -112,13 +115,13 @@ GEM
112115
lumberjack (1.2.8)
113116
memory_profiler (0.9.14)
114117
method_source (1.0.0)
115-
mini_portile2 (2.8.1)
118+
mini_portile2 (2.8.8)
116119
minitest (5.18.0)
117120
multi_json (1.15.0)
118121
nenv (0.3.0)
119-
nio4r (2.5.8)
120-
nokogiri (1.13.10)
121-
mini_portile2 (~> 2.8.0)
122+
nio4r (2.7.0)
123+
nokogiri (1.16.8)
124+
mini_portile2 (~> 2.8.2)
122125
racc (~> 1.4)
123126
notiffany (0.1.3)
124127
nenv (~> 0.1)
@@ -129,9 +132,9 @@ GEM
129132
parallel (1.22.1)
130133
parser (3.2.1.1)
131134
ast (~> 2.4.1)
132-
pg (1.4.6)
133-
pg_query (2.2.1)
134-
google-protobuf (>= 3.19.2)
135+
pg (1.5.9)
136+
pg_query (5.1.0)
137+
google-protobuf (>= 3.22.3)
135138
protocol-hpack (1.4.2)
136139
protocol-http (0.23.12)
137140
protocol-http1 (0.14.6)
@@ -157,7 +160,7 @@ GEM
157160
binding_of_caller (~> 1.0)
158161
pry (~> 0.13)
159162
public_suffix (5.0.1)
160-
racc (1.6.2)
163+
racc (1.8.1)
161164
rack (3.0.7)
162165
rainbow (3.1.1)
163166
rake (13.0.6)
@@ -240,6 +243,8 @@ DEPENDENCIES
240243
guard-rspec (~> 4.7)
241244
guard-rubocop (~> 1.5.0)
242245
memory_profiler (~> 0.9)
246+
nio4r (= 2.7.0)
247+
nokogiri (= 1.16.8)
243248
pry
244249
pry-alias
245250
pry-doc

‎arel_toolkit.gemspec

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ Gem::Specification.new do |spec|
2727
spec.extensions = ['ext/pg_result_init/extconf.rb']
2828

2929
spec.add_dependency 'activerecord', '>= 6.1', '< 7'
30-
spec.add_dependency 'pg', '>= 1.1.4'
31-
spec.add_dependency 'pg_query', '~> 2.2'
30+
spec.add_dependency 'pg', '>= 1.5.9'
31+
spec.add_dependency 'pg_query', '~> 5.1'
3232

3333
spec.add_development_dependency 'bundler', '~> 2.0'
3434
spec.add_development_dependency 'dpl', '~> 1.10.11'
3535
spec.add_development_dependency 'github_changelog_generator', '~> 1.15'
36+
spec.add_development_dependency 'nio4r', '= 2.7.0'
37+
spec.add_development_dependency 'nokogiri', '= 1.16.8'
3638
spec.add_development_dependency 'rake', '~> 13.0'
3739
spec.add_development_dependency 'rake-compiler', '~> 1.0'
3840
spec.add_development_dependency 'rspec', '~> 3.8'

‎lib/arel/sql_to_arel/pg_query_visitor.rb

+17-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ def visit_A_ArrayExpr(attribute)
3838
end
3939

4040
def visit_A_Const(attribute)
41-
visit(attribute.val, :const)
41+
if attribute.val.nil?
42+
visit_Null(attribute)
43+
else
44+
visit(attribute.send(attribute.val), :const)
45+
end
4246
end
4347

4448
def visit_A_Expr(attribute)
@@ -172,7 +176,11 @@ def visit_Alias(attribute)
172176
end
173177

174178
def visit_BitString(attribute)
175-
Arel::Nodes::BitString.new(attribute.str)
179+
Arel::Nodes::BitString.new(attribute.bsval)
180+
end
181+
182+
def visit_Boolean(attribute)
183+
attribute.boolval ? Arel::Nodes::True.new : Arel::Nodes::False.new
176184
end
177185

178186
def visit_BoolExpr(attribute, context = false)
@@ -298,7 +306,7 @@ def visit_DeleteStmt(attribute)
298306
end
299307

300308
def visit_Float(attribute)
301-
Arel::Nodes::SqlLiteral.new attribute.str
309+
Arel::Nodes::SqlLiteral.new attribute.fval
302310
end
303311

304312
# https://github.com/postgres/postgres/blob/REL_10_1/src/include/nodes/parsenodes.h
@@ -682,6 +690,10 @@ def visit_SelectStmt(attribute, context = nil)
682690
value
683691
when Arel::Nodes::Quoted
684692
value.value
693+
when Arel::Nodes::True
694+
true
695+
when Arel::Nodes::False
696+
false
685697
else
686698
boom "Unknown value `#{value}`"
687699
end
@@ -777,9 +789,9 @@ def visit_SQLValueFunction(attribute)
777789
def visit_String(attribute, context = nil)
778790
case context
779791
when :operator
780-
attribute.str
792+
attribute.sval
781793
when :const
782-
Arel::Nodes.build_quoted attribute.str
794+
Arel::Nodes.build_quoted attribute.sval
783795
else
784796
"\"#{attribute}\""
785797
end

‎lib/arel/sql_to_arel/pg_query_visitor/frame_options.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def frameoptions
8484
case PG.library_version.to_s[0, 2]
8585
when '09', '10'
8686
FRAMEOPTIONS_V10
87-
when '11', '12', '13', '14', '15'
87+
when '11', '12', '13', '14', '15', '16', '17'
8888
FRAMEOPTIONS_V11_AND_UP
8989
else
9090
raise "Version #{PG.library_version.to_s[0, 2]} not supported"

‎spec/arel/sql_to_arel_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@
102102
visit 'select', 'COUNT(DISTINCT "some_column")'
103103
visit 'select', "\"posts\".\"created_at\"::timestamp with time zone AT TIME ZONE 'Etc/UTC'"
104104
visit 'select', "(1 - 1) AT TIME ZONE 'Etc/UTC'"
105-
visit 'select', 'extract(\'epoch\' from "posts"."created_at")'
106-
visit 'select', 'extract(\'hour\' from "posts"."updated_at")'
105+
visit 'select', 'extract(\'epoch\' from "posts"."created_at")', sql_to_arel: false
106+
visit 'select', 'extract(\'hour\' from "posts"."updated_at")', sql_to_arel: false
107107
visit 'select',
108108
"('2001-02-1'::date, '2001-12-21'::date) OVERLAPS ('2001-10-30'::date, '2002-10-30'::date)"
109109
visit 'select', 'some_function("a", \'b\', 1)'
@@ -171,7 +171,7 @@
171171
# https://github.com/mvgijssel/arel_toolkit/issues/57
172172
# visit 'sql', '???', sql_to_arel: false
173173
visit 'select', '$1'
174-
visit 'select', '?, ?', expected_sql: 'SELECT $1, $2'
174+
visit 'select', '?, ?', sql_to_arel: false
175175
# https://github.com/mvgijssel/arel_toolkit/issues/101
176176
visit 'sql',
177177
'PREPARE some_plan (integer) AS (SELECT $1)',
@@ -301,7 +301,7 @@
301301
visit 'select', '2.0 ^ 3.0'
302302
visit 'select', ' |/ 16'
303303
visit 'select', ' ||/ 17'
304-
visit 'select', '14 !'
304+
visit 'select', '14 !', sql_to_arel: false
305305
visit 'select', '!! 15'
306306
visit 'select', ' @ -5'
307307
visit 'select', '2 & 3'
@@ -557,8 +557,8 @@
557557
visit 'select', "date_part('month', '2 years 3 months'::interval)"
558558
visit 'select', "date_trunc('hour', '2001-02-16 20:38:40'::timestamp)"
559559
visit 'select', "date_trunc('hour', '2 days 3 hours 40 minutes'::interval)"
560-
visit 'select', "extract('hour' from '2001-02-16 20:38:40'::timestamp)"
561-
visit 'select', "extract('month' from '2 years 3 months'::interval)"
560+
visit 'select', "extract('hour' from '2001-02-16 20:38:40'::timestamp)", sql_to_arel: false
561+
visit 'select', "extract('month' from '2 years 3 months'::interval)", sql_to_arel: false
562562
visit 'select', "isfinite('2001-02-16'::date)"
563563
visit 'select', "isfinite('2001-02-16 21:28:30'::timestamp)"
564564
visit 'select', "isfinite('4 hours'::interval)"

‎spec/arel/transformer/prefix_schema_name_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
prefixed_sql = transformer.call(arel.first, next_middleware).to_sql
6060

6161
expect(prefixed_sql).to eq(
62-
'SELECT "posts"."id" FROM "secret"."posts" INNER JOIN "public"."users" ON \'t\'::bool',
62+
'SELECT "posts"."id" FROM "secret"."posts" INNER JOIN "public"."users" ON TRUE',
6363
)
6464
end
6565

‎spec/postgres_ext_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def self.call(arel, next_middleware)
2929
it 'works for Score.with CTE' do
3030
game = Game.create!
3131
score = Score.create! game: game
32-
_other_score = Score.create! game: Game.create!
32+
_other_score = Score.create!(game: Game.create!)
3333
query = Score
3434
.with(my_games: Game.where(id: game))
3535
.joins('INNER JOIN "my_games" ON "scores"."game_id" = "my_games"."id" ')
@@ -52,8 +52,8 @@ def self.call(arel, next_middleware)
5252
Arel.middleware.apply([PostgresExtMiddleware]) do
5353
game = Game.create!
5454
user = User.create!
55-
score = Score.create! game: game, user: user
56-
_other_score = Score.create! game: Game.create!, user: User.create!
55+
score = Score.create!(game: game, user: user)
56+
_other_score = Score.create!(game: Game.create!, user: User.create!)
5757
query = Score.from_cte('scores_for_game', Score.where(game_id: game)).where(user_id: user)
5858

5959
expect(PostgresExtMiddleware).to receive(:call).and_wrap_original do |m, arel, context|

0 commit comments

Comments
 (0)
Please sign in to comment.