Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
prog-supdex authored and palkan committed Oct 27, 2023
1 parent 607bc92 commit d4de0ab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
11 changes: 6 additions & 5 deletions lib/activerecord_slotted_counters/adapters/mysql_upsert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
module ActiveRecordSlottedCounters
module Adapters
class MysqlUpsert
attr_reader :klass, :current_adapter_name
attr_reader :klass

def initialize(klass, current_adapter_name)
def initialize(klass)
@klass = klass
@current_adapter_name = current_adapter_name
end

def apply?
def apply?(current_adapter_name)
return false unless defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)

current_adapter_name == ActiveRecord::ConnectionAdapters::Mysql2Adapter::ADAPTER_NAME
end

def bulk_insert(attributes, on_duplicate: nil, unique_by: nil)
def bulk_insert(attributes, on_duplicate: nil, **)
raise ArgumentError, "Values must not be empty" if attributes.empty?

keys = attributes.first.keys + klass.all_timestamp_attributes_in_model
Expand Down Expand Up @@ -58,6 +57,7 @@ def columns_for_attributes(attributes)
def quote_column_names(columns, table_name: false)
columns.map do |column|
column_name = klass.connection.quote_column_name(column.name)

if table_name
"#{klass.quoted_table_name}.#{column_name}"
else
Expand All @@ -71,6 +71,7 @@ def quote_record(columns, record_values)
type = klass.connection.lookup_cast_type_from_column(columns[i])
klass.connection.quote(type.serialize(value))
end.join(",")

"(#{values_str})"
end

Expand Down
5 changes: 2 additions & 3 deletions lib/activerecord_slotted_counters/adapters/rails_upsert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
module ActiveRecordSlottedCounters
module Adapters
class RailsUpsert
attr_reader :klass, :current_adapter_name
attr_reader :klass

def initialize(klass, current_adapter_name)
def initialize(klass)
@klass = klass
@current_adapter_name = current_adapter_name
end

def apply?(_)
Expand Down

0 comments on commit d4de0ab

Please sign in to comment.