Class: ActiveRecord::Refined::Dialect::MysqlCompat
- Inherits:
-
Dialect
- Object
- Dialect
- ActiveRecord::Refined::Dialect::MysqlCompat
show all
- Includes:
- MysqlishJsonFunctions
- Defined in:
- lib/active_record/refined/dialect/mysql_compat.rb
Overview
What MySQL and MariaDB share, which is most of it; the two part company
only in the Mysql and Mariadb subclasses.
Instance Method Summary
collapse
-
#bit_count(expr, _model) ⇒ Object
-
#bitwise_operators_supported? ⇒ Boolean
-
#bitwise_xor(left, right) ⇒ Object
-
#check_string_aggregate_window(model) ⇒ Object
-
#excluded(column, model) ⇒ Object
The excluded row is VALUES(column), which takes the column bare.
-
#filter_supported? ⇒ Boolean
-
#full_outer_join_supported? ⇒ Boolean
-
#grouping_by_with_rollup? ⇒ Boolean
-
#grouping_supported?(kind) ⇒ Boolean
-
#json_aggregate_filter_supported? ⇒ Boolean
-
#json_argument(value, _model) ⇒ Object
A Ruby document or boolean written where the JSON functions want JSON is marked as it by reading it out whole: JSON_EXTRACT($).
-
#json_contains(document, json, _model) ⇒ Object
-
#json_has_key(document, _name, path, _model) ⇒ Object
-
#json_keys(document, _model) ⇒ Object
-
#json_list_by_element? ⇒ Boolean
-
#json_path(document, dollar_path, _steps, json_value, _model) ⇒ Object
-
#string_agg(operand, separator, orders, _string, model) ⇒ Object
GROUP_CONCAT, its separator a keyword after the operand and after the ORDER BY when there is one.
#json_build, #json_remove, #json_set
Instance Method Details
#bit_count(expr, _model) ⇒ Object
18
19
20
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 18
def bit_count(expr, _model)
AST::Function.new("BIT_COUNT", [expr])
end
|
#bitwise_operators_supported? ⇒ Boolean
16
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 16
def bitwise_operators_supported? = true
|
#bitwise_xor(left, right) ⇒ Object
28
29
30
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 28
def bitwise_xor(left, right)
Arel::Nodes::BitwiseXor.new(left, right)
end
|
#check_string_aggregate_window(model) ⇒ Object
70
71
72
73
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 70
def check_string_aggregate_window(model)
raise NotImplementedError,
"string_agg over a window has no equivalent on #{model.connection_db_config.adapter}"
end
|
#excluded(column, model) ⇒ Object
The excluded row is VALUES(column), which takes the column bare.
23
24
25
26
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 23
def excluded(column, model)
quoted = model.with_connection { |connection| connection.quote_column_name(column) }
AST::Function.new("VALUES", [Arel::Nodes::SqlLiteral.new(quoted)])
end
|
#filter_supported? ⇒ Boolean
15
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 15
def filter_supported? = false
|
#full_outer_join_supported? ⇒ Boolean
14
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 14
def full_outer_join_supported? = false
|
#grouping_by_with_rollup? ⇒ Boolean
79
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 79
def grouping_by_with_rollup? = true
|
#grouping_supported?(kind) ⇒ Boolean
77
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 77
def grouping_supported?(kind) = kind == :rollup
|
#json_aggregate_filter_supported? ⇒ Boolean
60
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 60
def json_aggregate_filter_supported? = false
|
#json_argument(value, _model) ⇒ Object
A Ruby document or boolean written where the JSON functions want
JSON is marked as it by reading it out whole: JSON_EXTRACT($).
54
55
56
57
58
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 54
def json_argument(value, _model)
json = Arel::Nodes.build_quoted(JSON.generate(value))
Arel::Nodes::NamedFunction.new(
"JSON_EXTRACT", [json, Arel::Nodes.build_quoted("$")])
end
|
#json_contains(document, json, _model) ⇒ Object
39
40
41
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 39
def json_contains(document, json, _model)
Arel::Nodes::NamedFunction.new("JSON_CONTAINS", [document, json])
end
|
#json_has_key(document, _name, path, _model) ⇒ Object
43
44
45
46
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 43
def json_has_key(document, _name, path, _model)
Arel::Nodes::NamedFunction.new(
"JSON_CONTAINS_PATH", [document, Arel::Nodes.build_quoted("one"), path])
end
|
#json_keys(document, _model) ⇒ Object
48
49
50
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 48
def json_keys(document, _model)
Arel::Nodes::NamedFunction.new("JSON_KEYS", [document])
end
|
#json_list_by_element? ⇒ Boolean
75
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 75
def json_list_by_element? = true
|
#json_path(document, dollar_path, _steps, json_value, _model) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 32
def json_path(document, dollar_path, _steps, json_value, _model)
= Arel::Nodes::NamedFunction.new(
"JSON_EXTRACT", [document, Arel::Nodes.build_quoted(dollar_path)])
return if json_value
Arel::Nodes::NamedFunction.new("JSON_UNQUOTE", [])
end
|
#string_agg(operand, separator, orders, _string, model) ⇒ Object
GROUP_CONCAT, its separator a keyword after the operand and after
the ORDER BY when there is one.
64
65
66
67
68
|
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 64
def string_agg(operand, separator, orders, _string, model)
order = orders.empty? ? "" : " ORDER BY #{compile_list(orders, model)}"
Arel.sql("GROUP_CONCAT(#{compile(operand, model)}#{order} " \
"SEPARATOR #{quote(separator, model)})")
end
|