arel_toolkit 0.2.0 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.codeclimate.yml +3 -0
- data/.github/workflows/develop.yml +90 -0
- data/.github/workflows/master.yml +67 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +13 -2
- data/Appraisals +13 -0
- data/CHANGELOG.md +132 -6
- data/Gemfile +5 -0
- data/Gemfile.lock +92 -12
- data/Guardfile +23 -12
- data/README.md +104 -6
- data/Rakefile +18 -0
- data/arel_toolkit.gemspec +19 -4
- data/benchmark.rb +54 -0
- data/bin/console +1 -0
- data/ext/pg_result_init/extconf.rb +52 -0
- data/ext/pg_result_init/pg_result_init.c +138 -0
- data/ext/pg_result_init/pg_result_init.h +6 -0
- data/gemfiles/active_record_6.gemfile +7 -0
- data/gemfiles/active_record_6.gemfile.lock +210 -0
- data/gemfiles/arel_gems.gemfile +10 -0
- data/gemfiles/arel_gems.gemfile.lock +284 -0
- data/gemfiles/default.gemfile +5 -0
- data/gemfiles/default.gemfile.lock +208 -0
- data/lib/arel/enhance.rb +17 -0
- data/lib/arel/enhance/context_enhancer/arel_table.rb +92 -0
- data/lib/arel/enhance/node.rb +232 -0
- data/lib/arel/enhance/path.rb +38 -0
- data/lib/arel/enhance/path_node.rb +26 -0
- data/lib/arel/enhance/query.rb +38 -0
- data/lib/arel/enhance/query_methods.rb +23 -0
- data/lib/arel/enhance/visitor.rb +97 -0
- data/lib/arel/extensions.rb +55 -3
- data/lib/arel/extensions/active_model_attribute_with_cast_value.rb +22 -0
- data/lib/arel/extensions/active_record_relation_query_attribute.rb +22 -0
- data/lib/arel/extensions/active_record_type_caster_connection.rb +7 -0
- data/lib/arel/extensions/active_record_type_caster_map.rb +7 -0
- data/lib/arel/extensions/array.rb +2 -9
- data/lib/arel/extensions/assignment.rb +22 -0
- data/lib/arel/extensions/at_time_zone.rb +37 -0
- data/lib/arel/extensions/attributes_attribute.rb +47 -0
- data/lib/arel/extensions/binary.rb +7 -0
- data/lib/arel/extensions/bind_param.rb +15 -0
- data/lib/arel/extensions/bit_string.rb +2 -9
- data/lib/arel/extensions/case.rb +17 -0
- data/lib/arel/extensions/coalesce.rb +17 -3
- data/lib/arel/extensions/conflict.rb +9 -0
- data/lib/arel/extensions/contained_within_equals.rb +10 -0
- data/lib/arel/extensions/contains.rb +27 -5
- data/lib/arel/extensions/contains_equals.rb +10 -0
- data/lib/arel/extensions/current_catalog.rb +4 -0
- data/lib/arel/extensions/current_date.rb +4 -0
- data/lib/arel/extensions/current_of_expression.rb +2 -9
- data/lib/arel/extensions/current_role.rb +4 -0
- data/lib/arel/extensions/current_row.rb +7 -0
- data/lib/arel/extensions/current_schema.rb +4 -0
- data/lib/arel/extensions/current_user.rb +4 -0
- data/lib/arel/extensions/dealocate.rb +31 -0
- data/lib/arel/extensions/default_values.rb +4 -0
- data/lib/arel/extensions/delete_manager.rb +25 -0
- data/lib/arel/extensions/delete_statement.rb +32 -8
- data/lib/arel/extensions/distinct_from.rb +3 -16
- data/lib/arel/extensions/dot.rb +11 -0
- data/lib/arel/extensions/equality.rb +2 -4
- data/lib/arel/extensions/exists.rb +59 -0
- data/lib/arel/extensions/extract_from.rb +25 -0
- data/lib/arel/extensions/factorial.rb +10 -2
- data/lib/arel/extensions/false.rb +7 -0
- data/lib/arel/extensions/function.rb +44 -14
- data/lib/arel/extensions/greatest.rb +17 -3
- data/lib/arel/extensions/indirection.rb +3 -12
- data/lib/arel/extensions/infer.rb +7 -7
- data/lib/arel/extensions/infix_operation.rb +17 -0
- data/lib/arel/extensions/insert_manager.rb +21 -0
- data/lib/arel/extensions/insert_statement.rb +35 -9
- data/lib/arel/extensions/into.rb +21 -0
- 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/least.rb +17 -3
- data/lib/arel/extensions/named_argument.rb +24 -0
- data/lib/arel/extensions/named_function.rb +7 -0
- data/lib/arel/extensions/node.rb +10 -0
- data/lib/arel/extensions/not_distinct_from.rb +3 -16
- data/lib/arel/extensions/not_equal.rb +2 -4
- data/lib/arel/extensions/ordering.rb +21 -6
- data/lib/arel/extensions/overlap.rb +1 -1
- data/lib/arel/extensions/overlaps.rb +49 -0
- data/lib/arel/extensions/overlay.rb +53 -0
- data/lib/arel/extensions/position.rb +27 -0
- data/lib/arel/extensions/prepare.rb +39 -0
- data/lib/arel/extensions/range_function.rb +10 -2
- data/lib/arel/extensions/row.rb +3 -8
- data/lib/arel/extensions/select_core.rb +73 -0
- data/lib/arel/extensions/select_manager.rb +25 -0
- data/lib/arel/extensions/select_statement.rb +31 -9
- data/lib/arel/extensions/session_user.rb +4 -0
- data/lib/arel/extensions/set_to_default.rb +4 -0
- data/lib/arel/extensions/substring.rb +46 -0
- data/lib/arel/extensions/table.rb +43 -10
- data/lib/arel/extensions/time_with_precision.rb +6 -0
- data/lib/arel/extensions/to_sql.rb +27 -0
- data/lib/arel/extensions/top.rb +8 -0
- data/lib/arel/extensions/transaction.rb +45 -0
- data/lib/arel/extensions/tree_manager.rb +15 -0
- data/lib/arel/extensions/trim.rb +44 -0
- data/lib/arel/extensions/true.rb +7 -0
- data/lib/arel/extensions/type_cast.rb +11 -0
- data/lib/arel/extensions/unary.rb +7 -0
- data/lib/arel/extensions/unary_operation.rb +16 -0
- data/lib/arel/extensions/unknown.rb +4 -0
- data/lib/arel/extensions/update_manager.rb +25 -0
- data/lib/arel/extensions/update_statement.rb +31 -6
- data/lib/arel/extensions/user.rb +4 -0
- data/lib/arel/extensions/values_list.rb +15 -0
- data/lib/arel/extensions/variable_set.rb +55 -0
- data/lib/arel/extensions/variable_show.rb +26 -0
- data/lib/arel/middleware.rb +27 -0
- data/lib/arel/middleware/active_record_extension.rb +13 -0
- data/lib/arel/middleware/cache_accessor.rb +35 -0
- data/lib/arel/middleware/chain.rb +172 -0
- data/lib/arel/middleware/database_executor.rb +77 -0
- data/lib/arel/middleware/no_op_cache.rb +9 -0
- data/lib/arel/middleware/postgresql_adapter.rb +62 -0
- data/lib/arel/middleware/railtie.rb +25 -0
- data/lib/arel/middleware/result.rb +170 -0
- data/lib/arel/middleware/to_sql_executor.rb +15 -0
- data/lib/arel/middleware/to_sql_middleware.rb +33 -0
- data/lib/arel/sql_to_arel.rb +8 -4
- data/lib/arel/sql_to_arel/error.rb +6 -0
- data/lib/arel/sql_to_arel/pg_query_visitor.rb +324 -76
- data/lib/arel/sql_to_arel/pg_query_visitor/frame_options.rb +112 -0
- data/lib/arel/sql_to_arel/result.rb +30 -0
- data/lib/arel/transformer.rb +8 -0
- data/lib/arel/transformer/prefix_schema_name.rb +183 -0
- data/lib/arel/transformer/remove_active_record_info.rb +40 -0
- data/lib/arel/transformer/replace_table_with_subquery.rb +31 -0
- data/lib/arel_toolkit.rb +16 -1
- data/lib/arel_toolkit/version.rb +1 -1
- metadata +278 -25
- data/.travis.yml +0 -21
- data/lib/arel/extensions/generate_series.rb +0 -9
- data/lib/arel/extensions/rank.rb +0 -9
- data/lib/arel/sql_to_arel/frame_options.rb +0 -110
- data/lib/arel/sql_to_arel/unbound_column_reference.rb +0 -5
|
@@ -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,59 @@
|
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
|
3
|
+
|
|
4
|
+
module Arel
|
|
5
|
+
module Nodes
|
|
6
|
+
# This is a copy of https://github.com/rails/arel/blob/v9.0.0/lib/arel/nodes/function.rb
|
|
7
|
+
# Only difference is the superclass, because EXISTS is not a function but a subquery expression.
|
|
8
|
+
# Semantic meaning is important when transforming the Arel using the enhanced AST,
|
|
9
|
+
# because EXISTS cannot be processed as a function. For example it does not have a schema
|
|
10
|
+
# like a normal function.
|
|
11
|
+
#
|
|
12
|
+
# To change the superclass we're removing the existing Exists class `Arel::Nodes::Exists`
|
|
13
|
+
# and recreating it extending from `Arel::Nodes::Unary`.
|
|
14
|
+
remove_const(:Exists)
|
|
15
|
+
|
|
16
|
+
# https://www.postgresql.org/docs/10/functions-subquery.html
|
|
17
|
+
class Exists < Arel::Nodes::Unary
|
|
18
|
+
include Arel::Predications
|
|
19
|
+
include Arel::WindowPredications
|
|
20
|
+
include Arel::OrderPredications
|
|
21
|
+
attr_accessor :expressions, :alias, :distinct
|
|
22
|
+
|
|
23
|
+
def initialize(expr, aliaz = nil)
|
|
24
|
+
@expressions = expr
|
|
25
|
+
@alias = aliaz && SqlLiteral.new(aliaz)
|
|
26
|
+
@distinct = false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def as(aliaz)
|
|
30
|
+
self.alias = SqlLiteral.new(aliaz)
|
|
31
|
+
self
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def hash
|
|
35
|
+
[@expressions, @alias, @distinct].hash
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def eql?(other)
|
|
39
|
+
self.class == other.class &&
|
|
40
|
+
expressions == other.expressions &&
|
|
41
|
+
self.alias == other.alias &&
|
|
42
|
+
distinct == other.distinct
|
|
43
|
+
end
|
|
44
|
+
alias == eql?
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
module Visitors
|
|
49
|
+
class Dot
|
|
50
|
+
def visit_Arel_Nodes_Exists(o)
|
|
51
|
+
visit_edge o, 'expressions'
|
|
52
|
+
visit_edge o, 'alias'
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# rubocop:enable Naming/MethodName
|
|
59
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
|
@@ -0,0 +1,25 @@
|
|
|
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::Binary
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module Visitors
|
|
12
|
+
class ToSql
|
|
13
|
+
def visit_Arel_Nodes_ExtractFrom(o, collector)
|
|
14
|
+
collector << 'extract('
|
|
15
|
+
visit o.right, collector
|
|
16
|
+
collector << ' from '
|
|
17
|
+
visit o.left, collector
|
|
18
|
+
collector << ')'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# rubocop:enable Naming/MethodName
|
|
25
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
module Arel
|
|
5
5
|
module Nodes
|
|
6
6
|
# https://www.postgresql.org/docs/9.4/functions-math.html
|
|
7
|
-
class Factorial < Arel::Nodes::
|
|
7
|
+
class Factorial < Arel::Nodes::Node
|
|
8
8
|
attr_accessor :prefix
|
|
9
|
+
attr_accessor :expr
|
|
9
10
|
|
|
10
11
|
def initialize(expr, prefix)
|
|
11
|
-
|
|
12
|
+
@expr = expr
|
|
12
13
|
@prefix = prefix
|
|
13
14
|
end
|
|
14
15
|
end
|
|
@@ -26,6 +27,13 @@ module Arel
|
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
29
|
end
|
|
30
|
+
|
|
31
|
+
class Dot
|
|
32
|
+
def visit_Arel_Nodes_Factorial(o)
|
|
33
|
+
visit_edge o, 'expr'
|
|
34
|
+
visit_edge o, 'prefix'
|
|
35
|
+
end
|
|
36
|
+
end
|
|
29
37
|
end
|
|
30
38
|
end
|
|
31
39
|
|
|
@@ -3,20 +3,27 @@
|
|
|
3
3
|
module Arel
|
|
4
4
|
module Nodes
|
|
5
5
|
# Postgres: https://www.postgresql.org/docs/9.1/functions-comparison.html
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
class Function
|
|
7
|
+
module FunctionExtension
|
|
8
|
+
# postgres only: https://www.postgresql.org/docs/9.5/functions-aggregate.html
|
|
9
|
+
attr_accessor :orders
|
|
10
|
+
attr_accessor :filter
|
|
11
|
+
attr_accessor :within_group
|
|
12
|
+
attr_accessor :variardic
|
|
13
|
+
# postgres only: https://www.postgresql.org/docs/10/ddl-schemas.html
|
|
14
|
+
attr_accessor :schema_name
|
|
15
|
+
|
|
16
|
+
def initialize(expr, aliaz = nil)
|
|
17
|
+
super
|
|
18
|
+
|
|
19
|
+
@expressions = expr
|
|
20
|
+
@alias = aliaz && SqlLiteral.new(aliaz)
|
|
21
|
+
@distinct = false
|
|
22
|
+
@orders = []
|
|
23
|
+
end
|
|
19
24
|
end
|
|
25
|
+
|
|
26
|
+
prepend FunctionExtension
|
|
20
27
|
end
|
|
21
28
|
end
|
|
22
29
|
|
|
@@ -26,6 +33,7 @@ module Arel
|
|
|
26
33
|
# rubocop:disable Metrics/CyclomaticComplexity
|
|
27
34
|
# rubocop:disable Metrics/AbcSize
|
|
28
35
|
def aggregate(name, o, collector)
|
|
36
|
+
collector << "#{o.schema_name}." if o.schema_name
|
|
29
37
|
collector << "#{name}("
|
|
30
38
|
collector << 'DISTINCT ' if o.distinct
|
|
31
39
|
collector << 'VARIADIC ' if o.variardic
|
|
@@ -38,7 +46,7 @@ module Arel
|
|
|
38
46
|
end
|
|
39
47
|
|
|
40
48
|
if o.orders.any?
|
|
41
|
-
collector <<
|
|
49
|
+
collector << ' ' unless o.within_group
|
|
42
50
|
collector << 'ORDER BY '
|
|
43
51
|
collector = inject_join o.orders, collector, ', '
|
|
44
52
|
end
|
|
@@ -62,6 +70,28 @@ module Arel
|
|
|
62
70
|
# rubocop:enable Metrics/CyclomaticComplexity
|
|
63
71
|
# rubocop:enable Metrics/AbcSize
|
|
64
72
|
end
|
|
73
|
+
|
|
74
|
+
class Dot
|
|
75
|
+
module FunctionExtension
|
|
76
|
+
def function(o)
|
|
77
|
+
super
|
|
78
|
+
|
|
79
|
+
visit_edge o, 'orders'
|
|
80
|
+
visit_edge o, 'filter'
|
|
81
|
+
visit_edge o, 'within_group'
|
|
82
|
+
visit_edge o, 'variardic'
|
|
83
|
+
visit_edge o, 'schema_name'
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
alias visit_Arel_Nodes_Min function
|
|
87
|
+
alias visit_Arel_Nodes_Max function
|
|
88
|
+
alias visit_Arel_Nodes_Avg function
|
|
89
|
+
alias visit_Arel_Nodes_Sum function
|
|
90
|
+
alias visit_Arel_Nodes_Count function
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
prepend FunctionExtension
|
|
94
|
+
end
|
|
65
95
|
end
|
|
66
96
|
end
|
|
67
97
|
|
|
@@ -1,9 +1,23 @@
|
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
|
3
|
+
|
|
1
4
|
module Arel
|
|
2
5
|
module Nodes
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
# https://www.postgresql.org/docs/10/functions-conditional.html
|
|
7
|
+
class Greatest < Arel::Nodes::Unary
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module Visitors
|
|
12
|
+
class ToSql
|
|
13
|
+
def visit_Arel_Nodes_Greatest(o, collector)
|
|
14
|
+
collector << 'GREATEST('
|
|
15
|
+
collector = inject_join(o.expr, collector, ', ')
|
|
16
|
+
collector << ')'
|
|
6
17
|
end
|
|
7
18
|
end
|
|
8
19
|
end
|
|
9
20
|
end
|
|
21
|
+
|
|
22
|
+
# rubocop:enable Naming/MethodName
|
|
23
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
|
@@ -3,25 +3,16 @@
|
|
|
3
3
|
|
|
4
4
|
module Arel
|
|
5
5
|
module Nodes
|
|
6
|
-
class Indirection < Arel::Nodes::
|
|
7
|
-
attr_reader :arg
|
|
8
|
-
attr_reader :indirection
|
|
9
|
-
|
|
10
|
-
def initialize(arg, indirection)
|
|
11
|
-
super()
|
|
12
|
-
|
|
13
|
-
@arg = arg
|
|
14
|
-
@indirection = indirection
|
|
15
|
-
end
|
|
6
|
+
class Indirection < Arel::Nodes::Binary
|
|
16
7
|
end
|
|
17
8
|
end
|
|
18
9
|
|
|
19
10
|
module Visitors
|
|
20
11
|
class ToSql
|
|
21
12
|
def visit_Arel_Nodes_Indirection(o, collector)
|
|
22
|
-
visit(o.
|
|
13
|
+
visit(o.left, collector)
|
|
23
14
|
collector << '['
|
|
24
|
-
visit(o.
|
|
15
|
+
visit(o.right, collector)
|
|
25
16
|
collector << ']'
|
|
26
17
|
end
|
|
27
18
|
end
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
module Arel
|
|
5
5
|
module Nodes
|
|
6
6
|
# https://www.postgresql.org/docs/9.5/sql-insert.html
|
|
7
|
-
class Infer < Arel::Nodes::
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
class Infer < Arel::Nodes::Binary
|
|
8
|
+
alias name left
|
|
9
|
+
alias indexes right
|
|
10
10
|
end
|
|
11
11
|
end
|
|
12
12
|
|
|
@@ -15,13 +15,13 @@ module Arel
|
|
|
15
15
|
def visit_Arel_Nodes_Infer(o, collector)
|
|
16
16
|
if o.name
|
|
17
17
|
collector << 'ON CONSTRAINT '
|
|
18
|
-
collector << o.
|
|
19
|
-
collector <<
|
|
18
|
+
collector << o.left
|
|
19
|
+
collector << ' '
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
if o.
|
|
22
|
+
if o.right
|
|
23
23
|
collector << '('
|
|
24
|
-
inject_join o.
|
|
24
|
+
inject_join o.right, collector, ', '
|
|
25
25
|
collector << ') '
|
|
26
26
|
end
|
|
27
27
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
|
3
|
+
|
|
4
|
+
module Arel
|
|
5
|
+
module Visitors
|
|
6
|
+
class Dot
|
|
7
|
+
def visit_Arel_Nodes_InfixOperation(o)
|
|
8
|
+
visit_edge o, 'operator'
|
|
9
|
+
visit_edge o, 'left'
|
|
10
|
+
visit_edge o, 'right'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# rubocop:enable Naming/MethodName
|
|
17
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
|
3
|
+
|
|
4
|
+
module Arel
|
|
5
|
+
class InsertManager < Arel::TreeManager
|
|
6
|
+
def ==(other)
|
|
7
|
+
other.is_a?(self.class) && @ast == other.ast
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
module Visitors
|
|
12
|
+
class Dot
|
|
13
|
+
def visit_Arel_InsertManager(o)
|
|
14
|
+
visit_edge o, 'ast'
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# rubocop:enable Naming/MethodName
|
|
21
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
|
@@ -3,12 +3,22 @@
|
|
|
3
3
|
|
|
4
4
|
module Arel
|
|
5
5
|
module Nodes
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
class InsertStatement
|
|
7
|
+
# https://www.postgresql.org/docs/9.5/sql-insert.html
|
|
8
|
+
module InsertStatementExtension
|
|
9
|
+
attr_accessor :with
|
|
10
|
+
attr_accessor :conflict
|
|
11
|
+
attr_accessor :override
|
|
12
|
+
attr_accessor :returning
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
super
|
|
16
|
+
|
|
17
|
+
@returning = []
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
prepend(InsertStatementExtension)
|
|
12
22
|
end
|
|
13
23
|
end
|
|
14
24
|
|
|
@@ -20,7 +30,7 @@ module Arel
|
|
|
20
30
|
def visit_Arel_Nodes_InsertStatement(o, collector)
|
|
21
31
|
if o.with
|
|
22
32
|
collector = visit o.with, collector
|
|
23
|
-
collector <<
|
|
33
|
+
collector << ' '
|
|
24
34
|
end
|
|
25
35
|
|
|
26
36
|
collector << 'INSERT INTO '
|
|
@@ -32,7 +42,7 @@ module Arel
|
|
|
32
42
|
end
|
|
33
43
|
|
|
34
44
|
case o.override
|
|
35
|
-
when 0
|
|
45
|
+
when nil, 0
|
|
36
46
|
collector << ''
|
|
37
47
|
when 1
|
|
38
48
|
collector << ' OVERRIDING USER VALUE'
|
|
@@ -50,18 +60,34 @@ module Arel
|
|
|
50
60
|
collector
|
|
51
61
|
end
|
|
52
62
|
|
|
63
|
+
visit(o.conflict, collector) if o.conflict
|
|
64
|
+
|
|
53
65
|
unless o.returning.empty?
|
|
54
66
|
collector << ' RETURNING '
|
|
55
67
|
collector = inject_join o.returning, collector, ', '
|
|
56
68
|
end
|
|
57
69
|
|
|
58
|
-
visit(o.on_conflict, collector) if o.on_conflict
|
|
59
70
|
collector
|
|
60
71
|
end
|
|
61
72
|
# rubocop:enable Metrics/CyclomaticComplexity
|
|
62
73
|
# rubocop:enable Metrics/AbcSize
|
|
63
74
|
# rubocop:enable Metrics/PerceivedComplexity
|
|
64
75
|
end
|
|
76
|
+
|
|
77
|
+
class Dot
|
|
78
|
+
module InsertStatementExtension
|
|
79
|
+
def visit_Arel_Nodes_InsertStatement(o)
|
|
80
|
+
super
|
|
81
|
+
|
|
82
|
+
visit_edge o, 'with'
|
|
83
|
+
visit_edge o, 'conflict'
|
|
84
|
+
visit_edge o, 'override'
|
|
85
|
+
visit_edge o, 'returning'
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
prepend(InsertStatementExtension)
|
|
90
|
+
end
|
|
65
91
|
end
|
|
66
92
|
end
|
|
67
93
|
|