Skip to content

Commit ca334db

Browse files
authored
Merge pull request taxjar#1 from AirHelp/rails5
Rails 5 support
2 parents a467e51 + 981f1ae commit ca334db

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

bulk_data_methods.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
1515
s.require_path = 'lib'
1616
s.homepage = 'http://github.com/fiksu/bulk_data_methods'
1717
s.add_dependency "pg"
18-
s.add_dependency "activerecord", '>= 3.0', '< 5.0'
19-
s.add_development_dependency "rails", '>= 3.0', '< 5.0'
18+
s.add_dependency "activerecord", '>= 3.0'
19+
s.add_development_dependency "rails", '>= 3.0'
2020
s.add_development_dependency "rspec-rails"
2121
end

lib/bulk_data_methods/bulk_methods_mixin.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def create_many(rows, options = {})
9797
end
9898
end
9999
column_values = column_names.map do |column_name|
100-
quote_value(row[column_name], columns_hash[column_name.to_s])
100+
bulk_methods_quote_value(columns_hash[column_name.to_s], row[column_name])
101101
end.join(',')
102102
"(#{column_values})"
103103
end.each_slice(options[:slice_size]) do |insert_slice|
@@ -226,9 +226,9 @@ def update_many(rows, options = {})
226226
column_name = column_name.to_s
227227
columns_hash_value = columns_hash[column_name]
228228
if i == 0
229-
"#{quote_value(column_value, columns_hash_value)}::#{columns_hash_value.sql_type} as #{column_name}"
229+
"#{bulk_methods_quote_value(columns_hash_value, column_value)}::#{columns_hash_value.sql_type} as #{column_name}"
230230
else
231-
quote_value(column_value, columns_hash_value)
231+
bulk_methods_quote_value(columns_hash_value, column_value)
232232
end
233233
end.join(',')
234234
end
@@ -251,4 +251,12 @@ def update_many(rows, options = {})
251251
end
252252
return returning
253253
end
254+
255+
def bulk_methods_quote_value(postgre_sql_column, column_value)
256+
if Rails.version >= '5.0.0'
257+
connection.quote connection.type_cast_from_column(postgre_sql_column, column_value)
258+
else
259+
quote_value(column_value, postgre_sql_column)
260+
end
261+
end
254262
end

0 commit comments

Comments
 (0)