Module: ActiveRecord::UpdateInBulk::AbstractAdapter
- Included in:
- ConnectionAdapters::AbstractAdapter
- Defined in:
- lib/activerecord-updateinbulk/adapters/abstract_adapter.rb
Overview
Extension points mixed into ActiveRecord::ConnectionAdapters::AbstractAdapter and consumed by the builder/visitor pipeline.
Concrete adapters may override any of these methods to describe their SQL capabilities and VALUES table semantics.
Instance Method Summary collapse
-
#supports_values_tables? ⇒ Boolean
Whether the database supports the SQL VALUES table constructor.
-
#typecast_values_table(values_table, columns) ⇒ Object
Hook for adapters that add explicit type casts to VALUES table entries so column types are correctly inferred by the database.
-
#values_table_default_column_names(width) ⇒ Object
Returns an array of
widthcolumn names used by the database for a VALUES table constructor of the given width. -
#values_table_requires_aliasing? ⇒ Boolean
Whether VALUES table serialization must always include explicit column aliases because there are no default names.
-
#values_table_row_prefix ⇒ Object
A string prepended to each row literal in the VALUES table constructor.
Instance Method Details
#supports_values_tables? ⇒ Boolean
Whether the database supports the SQL VALUES table constructor. When false, Relation#update_in_bulk raises ArgumentError.
12 13 14 |
# File 'lib/activerecord-updateinbulk/adapters/abstract_adapter.rb', line 12 def supports_values_tables? true end |
#typecast_values_table(values_table, columns) ⇒ Object
Hook for adapters that add explicit type casts to VALUES table entries so column types are correctly inferred by the database.
Receives the values_table (Arel::Nodes::ValuesTable) and columns (an array of ActiveRecord::ConnectionAdapters::Column).
Returns the typecasted Arel node: a new node or values_table itself, possibly modified in place.
The default implementation does no explicit type casting.
47 48 49 |
# File 'lib/activerecord-updateinbulk/adapters/abstract_adapter.rb', line 47 def typecast_values_table(values_table, columns) values_table end |
#values_table_default_column_names(width) ⇒ Object
Returns an array of width column names used by the database for a VALUES table constructor of the given width. These are the native names assigned to each column position when values_table_requires_aliasing? is false; otherwise they are alias conventions.
33 34 35 |
# File 'lib/activerecord-updateinbulk/adapters/abstract_adapter.rb', line 33 def values_table_default_column_names(width) (1..width).map { |i| "column#{i}" } end |
#values_table_requires_aliasing? ⇒ Boolean
Whether VALUES table serialization must always include explicit column aliases because there are no default names. This is a mariadb quirk.
25 26 27 |
# File 'lib/activerecord-updateinbulk/adapters/abstract_adapter.rb', line 25 def values_table_requires_aliasing? false end |
#values_table_row_prefix ⇒ Object
A string prepended to each row literal in the VALUES table constructor. Empty by default, per the standard. MySQL overrides this to "ROW" to produce VALUES ROW(1, 2), ROW(3, 4).
19 20 21 |
# File 'lib/activerecord-updateinbulk/adapters/abstract_adapter.rb', line 19 def values_table_row_prefix "" end |