arel_toolkit 0.1.0 → 0.2.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 +29 -0
- data/.gitignore +5 -0
- data/.rubocop.yml +34 -0
- data/.ruby-version +1 -1
- data/.travis.yml +16 -2
- data/CHANGELOG.md +10 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +94 -1
- data/Guardfile +42 -0
- data/README.md +23 -4
- data/Rakefile +3 -3
- data/arel_toolkit.gemspec +32 -15
- data/bin/console +4 -7
- data/lib/arel/extensions.rb +71 -0
- data/lib/arel/extensions/absolute.rb +10 -0
- data/lib/arel/extensions/all.rb +23 -0
- data/lib/arel/extensions/any.rb +23 -0
- data/lib/arel/extensions/array.rb +29 -0
- data/lib/arel/extensions/array_subselect.rb +23 -0
- data/lib/arel/extensions/between_symmetric.rb +23 -0
- data/lib/arel/extensions/bit_string.rb +27 -0
- data/lib/arel/extensions/bitwise_xor.rb +10 -0
- data/lib/arel/extensions/coalesce.rb +9 -0
- data/lib/arel/extensions/conflict.rb +47 -0
- data/lib/arel/extensions/contained_by.rb +10 -0
- data/lib/arel/extensions/contains.rb +10 -0
- data/lib/arel/extensions/cross_join.rb +21 -0
- data/lib/arel/extensions/cube_root.rb +10 -0
- data/lib/arel/extensions/current_catalog.rb +20 -0
- data/lib/arel/extensions/current_date.rb +20 -0
- data/lib/arel/extensions/current_of_expression.rb +29 -0
- data/lib/arel/extensions/current_role.rb +20 -0
- data/lib/arel/extensions/current_schema.rb +20 -0
- data/lib/arel/extensions/current_time.rb +22 -0
- data/lib/arel/extensions/current_timestamp.rb +22 -0
- data/lib/arel/extensions/current_user.rb +20 -0
- data/lib/arel/extensions/default_values.rb +21 -0
- data/lib/arel/extensions/delete_statement.rb +49 -0
- data/lib/arel/extensions/distinct_from.rb +22 -0
- data/lib/arel/extensions/equality.rb +30 -0
- data/lib/arel/extensions/except_all.rb +21 -0
- data/lib/arel/extensions/exponentiation.rb +10 -0
- data/lib/arel/extensions/factorial.rb +33 -0
- data/lib/arel/extensions/function.rb +68 -0
- data/lib/arel/extensions/generate_series.rb +9 -0
- data/lib/arel/extensions/greatest.rb +9 -0
- data/lib/arel/extensions/indirection.rb +32 -0
- data/lib/arel/extensions/infer.rb +35 -0
- data/lib/arel/extensions/insert_statement.rb +69 -0
- data/lib/arel/extensions/intersect_all.rb +21 -0
- data/lib/arel/extensions/lateral.rb +34 -0
- data/lib/arel/extensions/least.rb +9 -0
- data/lib/arel/extensions/local_time.rb +22 -0
- data/lib/arel/extensions/local_timestamp.rb +22 -0
- data/lib/arel/extensions/modulo.rb +10 -0
- data/lib/arel/extensions/named_function.rb +15 -0
- data/lib/arel/extensions/natural_join.rb +21 -0
- data/lib/arel/extensions/not_between.rb +22 -0
- data/lib/arel/extensions/not_between_symmetric.rb +23 -0
- data/lib/arel/extensions/not_distinct_from.rb +22 -0
- data/lib/arel/extensions/not_equal.rb +30 -0
- data/lib/arel/extensions/not_similar.rb +29 -0
- data/lib/arel/extensions/null_if.rb +24 -0
- data/lib/arel/extensions/ordering.rb +47 -0
- data/lib/arel/extensions/overlap.rb +10 -0
- data/lib/arel/extensions/range_function.rb +23 -0
- data/lib/arel/extensions/rank.rb +9 -0
- data/lib/arel/extensions/row.rb +30 -0
- data/lib/arel/extensions/select_statement.rb +26 -0
- data/lib/arel/extensions/session_user.rb +20 -0
- data/lib/arel/extensions/set_to_default.rb +21 -0
- data/lib/arel/extensions/similar.rb +32 -0
- data/lib/arel/extensions/square_root.rb +10 -0
- data/lib/arel/extensions/table.rb +49 -0
- data/lib/arel/extensions/time_with_precision.rb +13 -0
- data/lib/arel/extensions/type_cast.rb +30 -0
- data/lib/arel/extensions/unknown.rb +20 -0
- data/lib/arel/extensions/update_statement.rb +63 -0
- data/lib/arel/extensions/user.rb +20 -0
- data/lib/arel/extensions/with_ordinality.rb +22 -0
- data/lib/arel/sql_to_arel.rb +8 -0
- data/lib/arel/sql_to_arel/frame_options.rb +110 -0
- data/lib/arel/sql_to_arel/pg_query_visitor.rb +1005 -0
- data/lib/arel/sql_to_arel/unbound_column_reference.rb +5 -0
- data/lib/arel_toolkit.rb +4 -3
- data/lib/arel_toolkit/version.rb +1 -1
- metadata +250 -4
@@ -0,0 +1,21 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
class IntersectAll < Binary
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Visitors
|
11
|
+
class ToSql
|
12
|
+
def visit_Arel_Nodes_IntersectAll(o, collector)
|
13
|
+
collector << '( '
|
14
|
+
infix_value(o, collector, ' INTERSECT ALL ') << ' )'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# rubocop:enable Naming/MethodName
|
21
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
# https://github.com/mvgijssel/arel_toolkit/issues/46
|
7
|
+
class Lateral < Arel::Nodes::Unary
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Visitors
|
12
|
+
class ToSql
|
13
|
+
# https://github.com/mvgijssel/arel_toolkit/issues/46
|
14
|
+
def visit_Arel_Nodes_Lateral(o, collector)
|
15
|
+
collector << 'LATERAL '
|
16
|
+
grouping_parentheses o, collector
|
17
|
+
end
|
18
|
+
|
19
|
+
# https://github.com/mvgijssel/arel_toolkit/issues/46
|
20
|
+
def grouping_parentheses(o, collector)
|
21
|
+
if o.expr.is_a? Nodes::SelectStatement
|
22
|
+
collector << '('
|
23
|
+
visit o.expr, collector
|
24
|
+
collector << ')'
|
25
|
+
else
|
26
|
+
visit o.expr, collector
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# rubocop:enable Naming/MethodName
|
34
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
class LocalTime < TimeWithPrecision
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Visitors
|
11
|
+
class ToSql
|
12
|
+
def visit_Arel_Nodes_LocalTime(o, collector)
|
13
|
+
collector << 'localtime'
|
14
|
+
collector << "(#{o.precision.to_i})" if o.precision
|
15
|
+
collector
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# rubocop:enable Naming/MethodName
|
22
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
class LocalTimestamp < TimeWithPrecision
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Visitors
|
11
|
+
class ToSql
|
12
|
+
def visit_Arel_Nodes_LocalTimestamp(o, collector)
|
13
|
+
collector << 'localtimestamp'
|
14
|
+
collector << "(#{o.precision.to_i})" if o.precision
|
15
|
+
collector
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# rubocop:enable Naming/MethodName
|
22
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Visitors
|
6
|
+
class ToSql
|
7
|
+
def visit_Arel_Nodes_NamedFunction(o, collector)
|
8
|
+
aggregate(o.name, o, collector)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# rubocop:enable Naming/MethodName
|
15
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
class NaturalJoin < Arel::Nodes::Join
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Visitors
|
11
|
+
class ToSql
|
12
|
+
def visit_Arel_Nodes_NaturalJoin(o, collector)
|
13
|
+
collector << 'NATURAL JOIN '
|
14
|
+
visit o.left, collector
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# rubocop:enable Naming/MethodName
|
21
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
class NotBetween < Arel::Nodes::Between
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Visitors
|
11
|
+
class ToSql
|
12
|
+
def visit_Arel_Nodes_NotBetween(o, collector)
|
13
|
+
collector = visit o.left, collector
|
14
|
+
collector << ' NOT BETWEEN '
|
15
|
+
visit o.right, collector
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# rubocop:enable Naming/MethodName
|
22
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
# Postgres: https://www.postgresql.org/docs/9.1/functions-comparison.html
|
7
|
+
class NotBetweenSymmetric < Arel::Nodes::BetweenSymmetric
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Visitors
|
12
|
+
class ToSql
|
13
|
+
def visit_Arel_Nodes_NotBetweenSymmetric(o, collector)
|
14
|
+
collector = visit o.left, collector
|
15
|
+
collector << ' NOT BETWEEN SYMMETRIC '
|
16
|
+
visit o.right, collector
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# rubocop:enable Naming/MethodName
|
23
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
class NotDistinctFrom < Arel::Nodes::Binary
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Visitors
|
11
|
+
class ToSql
|
12
|
+
def visit_Arel_Nodes_NotDistinctFrom(o, collector)
|
13
|
+
visit o.left, collector
|
14
|
+
collector << ' IS NOT DISTINCT FROM '
|
15
|
+
visit o.right, collector
|
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 Visitors
|
6
|
+
class ToSql
|
7
|
+
def visit_Arel_Nodes_NotEqual(o, collector)
|
8
|
+
right = o.right
|
9
|
+
|
10
|
+
collector = visit o.left, collector
|
11
|
+
|
12
|
+
case right
|
13
|
+
when Arel::Nodes::Unknown, Arel::Nodes::False, Arel::Nodes::True
|
14
|
+
collector << ' IS NOT '
|
15
|
+
visit right, collector
|
16
|
+
|
17
|
+
when NilClass
|
18
|
+
collector << ' IS NOT NULL'
|
19
|
+
|
20
|
+
else
|
21
|
+
collector << ' != '
|
22
|
+
visit right, collector
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# rubocop:enable Naming/MethodName
|
30
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
# Postgres: https://www.postgresql.org/docs/9/functions-matching.html
|
7
|
+
class NotSimilar < Arel::Nodes::Similar
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Visitors
|
12
|
+
class ToSql
|
13
|
+
def visit_Arel_Nodes_NotSimilar(o, collector)
|
14
|
+
visit o.left, collector
|
15
|
+
collector << ' NOT SIMILAR TO '
|
16
|
+
visit o.right, collector
|
17
|
+
if o.escape
|
18
|
+
collector << ' ESCAPE '
|
19
|
+
visit o.escape, collector
|
20
|
+
else
|
21
|
+
collector
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# rubocop:enable Naming/MethodName
|
29
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
class NullIf < Arel::Nodes::Binary
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Visitors
|
11
|
+
class ToSql
|
12
|
+
def visit_Arel_Nodes_NullIf(o, collector)
|
13
|
+
collector << 'NULLIF('
|
14
|
+
visit o.left, collector
|
15
|
+
collector << ', '
|
16
|
+
visit o.right, collector
|
17
|
+
collector << ')'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# rubocop:enable Naming/MethodName
|
24
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
Arel::Nodes::Ordering.class_eval do
|
7
|
+
# Postgres: https://www.postgresql.org/docs/9.4/queries-order.html
|
8
|
+
attr_accessor :nulls
|
9
|
+
|
10
|
+
def initialize(expr, nulls = 0)
|
11
|
+
super(expr)
|
12
|
+
|
13
|
+
@nulls = nulls
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Visitors
|
19
|
+
class ToSql
|
20
|
+
alias old_visit_Arel_Nodes_Ascending visit_Arel_Nodes_Ascending
|
21
|
+
def visit_Arel_Nodes_Ascending(o, collector)
|
22
|
+
old_visit_Arel_Nodes_Ascending(o, collector)
|
23
|
+
apply_ordering_nulls(o, collector)
|
24
|
+
end
|
25
|
+
|
26
|
+
alias old_visit_Arel_Nodes_Descending visit_Arel_Nodes_Descending
|
27
|
+
def visit_Arel_Nodes_Descending(o, collector)
|
28
|
+
old_visit_Arel_Nodes_Descending(o, collector)
|
29
|
+
apply_ordering_nulls(o, collector)
|
30
|
+
end
|
31
|
+
|
32
|
+
def apply_ordering_nulls(o, collector)
|
33
|
+
case o.nulls
|
34
|
+
when 1
|
35
|
+
collector << ' NULLS FIRST'
|
36
|
+
when 2
|
37
|
+
collector << ' NULLS LAST'
|
38
|
+
else
|
39
|
+
collector
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# rubocop:enable Naming/MethodName
|
47
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# rubocop:disable Naming/MethodName
|
2
|
+
# rubocop:disable Naming/UncommunicativeMethodParamName
|
3
|
+
|
4
|
+
module Arel
|
5
|
+
module Nodes
|
6
|
+
# Postgres: https://www.postgresql.org/docs/9.4/sql-select.html
|
7
|
+
class RangeFunction < Arel::Nodes::Unary
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module Visitors
|
12
|
+
class ToSql
|
13
|
+
def visit_Arel_Nodes_RangeFunction(o, collector)
|
14
|
+
collector << 'ROWS FROM ('
|
15
|
+
visit o.expr, collector
|
16
|
+
collector << ')'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# rubocop:enable Naming/MethodName
|
23
|
+
# 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
|
+
# Postgres: https://www.postgresql.org/docs/9.2/sql-expressions.html
|
7
|
+
class Row < Arel::Nodes::Unary
|
8
|
+
attr_reader :row_format
|
9
|
+
|
10
|
+
def initialize(args, row_format)
|
11
|
+
super(args)
|
12
|
+
|
13
|
+
@row_format = row_format
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Visitors
|
19
|
+
class ToSql
|
20
|
+
def visit_Arel_Nodes_Row(o, collector)
|
21
|
+
collector << 'ROW('
|
22
|
+
visit o.expr, collector
|
23
|
+
collector << ')'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# rubocop:enable Naming/MethodName
|
30
|
+
# rubocop:enable Naming/UncommunicativeMethodParamName
|