arel_toolkit 0.3.0 → 0.4.0
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/.gitignore +4 -1
- data/.rubocop.yml +13 -5
- data/.travis.yml +7 -2
- data/Appraisals +9 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile +5 -0
- data/Gemfile.lock +22 -5
- data/README.md +59 -18
- data/arel_toolkit.gemspec +5 -1
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/arel_gems.gemfile +10 -0
- data/gemfiles/arel_gems.gemfile.lock +274 -0
- data/gemfiles/default.gemfile +5 -0
- data/gemfiles/default.gemfile.lock +198 -0
- data/lib/arel/enhance.rb +16 -0
- data/lib/arel/enhance/context_enhancer/arel_table.rb +75 -0
- data/lib/arel/enhance/node.rb +189 -0
- data/lib/arel/enhance/path.rb +38 -0
- data/lib/arel/enhance/path_node.rb +26 -0
- data/lib/arel/enhance/query.rb +36 -0
- data/lib/arel/enhance/visitor.rb +81 -0
- data/lib/arel/extensions.rb +24 -4
- data/lib/arel/extensions/active_record_type_caster_map.rb +7 -0
- data/lib/arel/extensions/array.rb +2 -9
- data/lib/arel/extensions/at_time_zone.rb +10 -3
- data/lib/arel/extensions/binary.rb +7 -0
- data/lib/arel/extensions/bit_string.rb +2 -9
- data/lib/arel/extensions/case.rb +17 -0
- data/lib/arel/extensions/conflict.rb +9 -0
- data/lib/arel/extensions/contains.rb +27 -5
- 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 +22 -6
- data/lib/arel/extensions/delete_statement.rb +26 -9
- data/lib/arel/extensions/dot.rb +11 -0
- data/lib/arel/extensions/extract_from.rb +3 -10
- data/lib/arel/extensions/factorial.rb +10 -2
- data/lib/arel/extensions/false.rb +7 -0
- data/lib/arel/extensions/function.rb +42 -13
- data/lib/arel/extensions/indirection.rb +3 -12
- data/lib/arel/extensions/infer.rb +6 -6
- data/lib/arel/extensions/infix_operation.rb +17 -0
- data/lib/arel/extensions/insert_manager.rb +19 -3
- data/lib/arel/extensions/insert_statement.rb +30 -11
- data/lib/arel/extensions/into.rb +21 -0
- data/lib/arel/extensions/named_argument.rb +3 -8
- data/lib/arel/extensions/named_function.rb +7 -0
- data/lib/arel/extensions/ordering.rb +21 -6
- data/lib/arel/extensions/overlaps.rb +9 -0
- data/lib/arel/extensions/overlay.rb +9 -0
- data/lib/arel/extensions/position.rb +3 -8
- data/lib/arel/extensions/prepare.rb +39 -0
- data/lib/arel/extensions/row.rb +3 -8
- data/lib/arel/extensions/select_core.rb +58 -0
- data/lib/arel/extensions/select_manager.rb +22 -6
- 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 +8 -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/transaction.rb +3 -8
- data/lib/arel/extensions/tree_manager.rb +10 -0
- data/lib/arel/extensions/trim.rb +8 -0
- data/lib/arel/extensions/true.rb +7 -0
- data/lib/arel/extensions/type_cast.rb +7 -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 +22 -6
- data/lib/arel/extensions/update_statement.rb +27 -10
- data/lib/arel/extensions/user.rb +4 -0
- data/lib/arel/extensions/values_list.rb +15 -0
- data/lib/arel/extensions/variable_set.rb +9 -0
- data/lib/arel/extensions/variable_show.rb +3 -8
- data/lib/arel/middleware/chain.rb +1 -5
- data/lib/arel/middleware/railtie.rb +10 -0
- data/lib/arel/sql_to_arel.rb +6 -3
- data/lib/arel/sql_to_arel/pg_query_visitor.rb +43 -15
- data/lib/arel/sql_to_arel/pg_query_visitor/frame_options.rb +1 -1
- data/lib/arel/sql_to_arel/result.rb +0 -4
- data/lib/arel/transformer.rb +7 -0
- data/lib/arel/transformer/add_schema_to_table.rb +26 -0
- data/lib/arel/transformer/remove_active_record_info.rb +42 -0
- data/lib/arel_toolkit.rb +8 -1
- data/lib/arel_toolkit/version.rb +1 -1
- metadata +81 -8
- data/lib/arel/extensions/unbound_column_reference.rb +0 -5
- data/lib/arel/sql_formatter.rb +0 -59
|
@@ -0,0 +1,31 @@
|
|
|
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_Dealocate(o)
|
|
8
|
+
visit_edge o, 'name'
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class ToSql
|
|
13
|
+
def visit_Arel_Nodes_Dealocate(o, collector)
|
|
14
|
+
collector << 'DEALLOCATE ' << (o.name || 'ALL')
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
module Nodes
|
|
20
|
+
class Dealocate < Node
|
|
21
|
+
attr_reader :name
|
|
22
|
+
|
|
23
|
+
def initialize(name)
|
|
24
|
+
@name = name
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# rubocop:enable Naming/MethodName
|
|
31
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
|
@@ -1,9 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
|
3
|
+
|
|
4
|
+
module Arel
|
|
5
|
+
class DeleteManager < Arel::TreeManager
|
|
6
|
+
def ==(other)
|
|
7
|
+
other.is_a?(self.class) && @ast == other.ast && @ctx == other.ctx
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
protected
|
|
5
11
|
|
|
6
|
-
|
|
12
|
+
attr_reader :ctx
|
|
13
|
+
end
|
|
7
14
|
|
|
8
|
-
|
|
15
|
+
module Visitors
|
|
16
|
+
class Dot
|
|
17
|
+
def visit_Arel_DeleteManager(o)
|
|
18
|
+
visit_edge o, 'ast'
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
9
22
|
end
|
|
23
|
+
|
|
24
|
+
# rubocop:enable Naming/MethodName
|
|
25
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
|
@@ -3,18 +3,21 @@
|
|
|
3
3
|
|
|
4
4
|
module Arel
|
|
5
5
|
module Nodes
|
|
6
|
-
# https://www.postgresql.org/docs/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
# https://www.postgresql.org/docs/10/sql-delete.html
|
|
7
|
+
class DeleteStatement
|
|
8
|
+
module DeleteStatementExtension
|
|
9
|
+
attr_accessor :using
|
|
10
|
+
attr_accessor :with
|
|
11
|
+
attr_accessor :returning
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
old_initialize(relation, wheres)
|
|
13
|
+
def initialize(relation = nil, wheres = [])
|
|
14
|
+
super
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
@returning = []
|
|
17
|
+
end
|
|
17
18
|
end
|
|
19
|
+
|
|
20
|
+
prepend DeleteStatementExtension
|
|
18
21
|
end
|
|
19
22
|
end
|
|
20
23
|
|
|
@@ -49,6 +52,20 @@ module Arel
|
|
|
49
52
|
end
|
|
50
53
|
# rubocop:enable Metrics/AbcSize
|
|
51
54
|
end
|
|
55
|
+
|
|
56
|
+
class Dot
|
|
57
|
+
module DeleteStatementExtension
|
|
58
|
+
def visit_Arel_Nodes_DeleteStatement(o)
|
|
59
|
+
super
|
|
60
|
+
|
|
61
|
+
visit_edge o, 'using'
|
|
62
|
+
visit_edge o, 'with'
|
|
63
|
+
visit_edge o, 'returning'
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
prepend(DeleteStatementExtension)
|
|
68
|
+
end
|
|
52
69
|
end
|
|
53
70
|
end
|
|
54
71
|
|
|
@@ -4,14 +4,7 @@
|
|
|
4
4
|
module Arel
|
|
5
5
|
module Nodes
|
|
6
6
|
# https://www.postgresql.org/docs/9.1/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
|
|
7
|
-
class ExtractFrom < Arel::Nodes::
|
|
8
|
-
attr_reader :field
|
|
9
|
-
|
|
10
|
-
def initialize(expr, field)
|
|
11
|
-
super(expr)
|
|
12
|
-
|
|
13
|
-
@field = field
|
|
14
|
-
end
|
|
7
|
+
class ExtractFrom < Arel::Nodes::Binary
|
|
15
8
|
end
|
|
16
9
|
end
|
|
17
10
|
|
|
@@ -19,9 +12,9 @@ module Arel
|
|
|
19
12
|
class ToSql
|
|
20
13
|
def visit_Arel_Nodes_ExtractFrom(o, collector)
|
|
21
14
|
collector << 'extract('
|
|
22
|
-
visit o.
|
|
15
|
+
visit o.right, collector
|
|
23
16
|
collector << ' from '
|
|
24
|
-
visit o.
|
|
17
|
+
visit o.left, collector
|
|
25
18
|
collector << ')'
|
|
26
19
|
end
|
|
27
20
|
end
|
|
@@ -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
|
|
@@ -62,6 +70,27 @@ 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
|
+
end
|
|
84
|
+
|
|
85
|
+
alias visit_Arel_Nodes_Exists function
|
|
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
|
+
end
|
|
91
|
+
|
|
92
|
+
prepend FunctionExtension
|
|
93
|
+
end
|
|
65
94
|
end
|
|
66
95
|
end
|
|
67
96
|
|
|
@@ -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.
|
|
18
|
+
collector << o.left
|
|
19
19
|
collector << SPACE
|
|
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
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
4
17
|
end
|
|
5
18
|
end
|
|
19
|
+
|
|
20
|
+
# rubocop:enable Naming/MethodName
|
|
21
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
|
@@ -3,19 +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 InsertStatementExtensions
|
|
9
|
+
attr_accessor :with
|
|
10
|
+
attr_accessor :conflict
|
|
11
|
+
attr_accessor :override
|
|
12
|
+
attr_accessor :returning
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
old_initialize
|
|
14
|
+
def initialize
|
|
15
|
+
super
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
@returning = []
|
|
18
|
+
end
|
|
18
19
|
end
|
|
20
|
+
|
|
21
|
+
prepend(InsertStatementExtensions)
|
|
19
22
|
end
|
|
20
23
|
end
|
|
21
24
|
|
|
@@ -57,18 +60,34 @@ module Arel
|
|
|
57
60
|
collector
|
|
58
61
|
end
|
|
59
62
|
|
|
63
|
+
visit(o.conflict, collector) if o.conflict
|
|
64
|
+
|
|
60
65
|
unless o.returning.empty?
|
|
61
66
|
collector << ' RETURNING '
|
|
62
67
|
collector = inject_join o.returning, collector, ', '
|
|
63
68
|
end
|
|
64
69
|
|
|
65
|
-
visit(o.conflict, collector) if o.conflict
|
|
66
70
|
collector
|
|
67
71
|
end
|
|
68
72
|
# rubocop:enable Metrics/CyclomaticComplexity
|
|
69
73
|
# rubocop:enable Metrics/AbcSize
|
|
70
74
|
# rubocop:enable Metrics/PerceivedComplexity
|
|
71
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
|
|
72
91
|
end
|
|
73
92
|
end
|
|
74
93
|
|