Class: ActiveRecord::Refined::Dialect::MysqlCompat

Inherits:
Dialect
  • Object
show all
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.

Direct Known Subclasses

Mariadb, Mysql

Constant Summary collapse

FUNCTIONS =
{ trunc: "TRUNCATE", date_trunc: nil, format: nil }.freeze

Instance Method Summary collapse

Instance Method Details

#bit_count(expr, _model) ⇒ Object



14
15
16
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 14

def bit_count(expr, _model)
  AST::Function.new("BIT_COUNT", [expr])
end

#bitwise_xor(left, right) ⇒ Object



24
25
26
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 24

def bitwise_xor(left, right)
  Arel::Nodes::BitwiseXor.new(left, right)
end

#check_string_aggregate_window(model) ⇒ Object

Raises:

  • (NotImplementedError)


54
55
56
57
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 54

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.



19
20
21
22
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 19

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

Returns:

  • (Boolean)


12
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 12

def filter_supported? = false

#full_outer_join_supported?Boolean

Returns:

  • (Boolean)


11
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 11

def full_outer_join_supported? = false

#grouping_by_with_rollup?Boolean

Returns:

  • (Boolean)


63
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 63

def grouping_by_with_rollup? = true

#grouping_supported?(kind) ⇒ Boolean

Returns:

  • (Boolean)


61
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 61

def grouping_supported?(kind) = kind == :rollup

#json_aggregate_filter_supported?Boolean

Returns:

  • (Boolean)


44
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 44

def json_aggregate_filter_supported? = false

#json_contains(document, json, _model) ⇒ Object



35
36
37
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 35

def json_contains(document, json, _model)
  Arel::Nodes::NamedFunction.new("JSON_CONTAINS", [document, json])
end

#json_has_key(document, _name, path, _model) ⇒ Object



39
40
41
42
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 39

def json_has_key(document, _name, path, _model)
  Arel::Nodes::NamedFunction.new(
    "JSON_CONTAINS_PATH", [document, Arel::Nodes.build_quoted("one"), path])
end

#json_list_by_element?Boolean

Returns:

  • (Boolean)


59
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 59

def json_list_by_element? = true

#json_path(document, dollar_path, _steps, json_value, _model) ⇒ Object



28
29
30
31
32
33
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 28

def json_path(document, dollar_path, _steps, json_value, _model)
  extracted = Arel::Nodes::NamedFunction.new(
    "JSON_EXTRACT", [document, Arel::Nodes.build_quoted(dollar_path)])
  return extracted if json_value
  Arel::Nodes::NamedFunction.new("JSON_UNQUOTE", [extracted])
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.



48
49
50
51
52
# File 'lib/active_record/refined/dialect/mysql_compat.rb', line 48

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