Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bulk_data_methods.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Gem::Specification.new do |s|
s.require_path = 'lib'
s.homepage = 'http://github.com/fiksu/bulk_data_methods'
s.add_dependency "pg"
s.add_dependency "activerecord", '>= 3.0', '< 5.0'
s.add_development_dependency "rails", '>= 3.0', '< 5.0'
s.add_dependency "activerecord", '>= 3.0'#, '< 5.0'
s.add_development_dependency "rails", '>= 3.0'
s.add_development_dependency "rspec-rails"
s.add_development_dependency "activeresource", '>= 3.0.0'
end
18 changes: 13 additions & 5 deletions lib/bulk_data_methods/mixin.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

module BulkDataMethods

# exception thrown when row data structures are inconsistent between rows in single call to {#create_many} or {#update_many}
Expand Down Expand Up @@ -105,7 +104,7 @@ def create_many(rows, options = {})
end
end
column_values = column_names.map do |column_name|
quote_value(row[column_name], columns_hash[column_name.to_s])
connection.quote(row[column_name], columns_hash[column_name.to_s])
end.join(',')
"(#{column_values})"
end.each_slice(options[:slice_size]) do |insert_slice|
Expand Down Expand Up @@ -236,9 +235,17 @@ def update_many(rows, options = {})
column_name = column_name.to_s
columns_hash_value = columns_hash[column_name]
if i == 0
"#{quote_value(column_value, columns_hash_value)}::#{columns_hash_value.sql_type} as #{column_name}"
if columns_hash_value.sql_type=="jsonb" && !column_value.nil? && !column_value!='NULL'
"'#{connection.quote(column_value)}'::#{columns_hash_value.sql_type} as #{column_name}"
else
"#{connection.quote(column_value)}::#{columns_hash_value.sql_type} as #{column_name}"
end
else
quote_value(column_value, columns_hash_value)
if columns_hash_value.sql_type=="jsonb" && !column_value.nil? && !column_value!='NULL'
"'#{connection.quote(column_value)}'"
else
connection.quote(column_value)
end
end
end.join(',')
end
Expand All @@ -257,7 +264,8 @@ def update_many(rows, options = {})
#{eval(returning_clause)}
SQL
sql = sql_update_string
#puts "SQL> #{sql}"
#binding.pry
#puts "SQL> #{sql}"
returning += find_by_sql(sql_update_string)
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# module ActiveRecord
# module ConnectionAdapters
# module PostgreSQL
# module Quoting
#
# private
# # ****** BEGIN PATCH ******
# # when column of postgresql is an array, call super and fail. for example with [2] or ["2"].
# # add condition for array elswhere call super
# # @param [Value]
# def _quote(value)
# case value
# when Array then "'{#{value.join(',')}}'"
# else
# super
# end
# end
# end
# end
# end
# end
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
require 'active_record'
require 'active_record/connection_adapters/abstract_adapter'
require 'active_record/connection_adapters/postgresql_adapter'
require 'active_record/connection_adapters/postgresql/quoting'

module ActiveRecord

module ConnectionAdapters

module PostgreSQL
module Quoting

private
# ****** BEGIN PATCH ******
# when column of postgresql is an array, call super and fail. for example with [2] or ["2"].
# add condition for array elswhere call super
# @param [Value]
def _quote(value)
case value
when Array then "'{#{value.join(',')}}'"
else
super
end
end
end
end
# Patches extending the postgres adapter with new operations for managing
# sequences (and sets of sequence values).
#
Expand Down
2 changes: 1 addition & 1 deletion lib/bulk_data_methods/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module BulkDataMethods
VERSION = "3.0.1"
VERSION = "3.0.5"
end