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
5 changes: 5 additions & 0 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
= This fork

Dan Sadaka changed the import_to_sql method to support multiple databases. Now use the model's connection
instead of the default.

= Crewait

Check out http://jonah.org/articles/crewait_go_.html for a guide to Crewait.
Expand Down
20 changes: 12 additions & 8 deletions lib/crewait.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def crewait(hash)
module HashMethods
def import_to_sql(model_class)
if model_class.respond_to? :table_name
model_class = model_class.table_name
model_table = model_class.table_name
else
model_table = model_class
end
keys = self.keys
values = []
Expand All @@ -86,13 +88,15 @@ def import_to_sql(model_class)
values = values.transpose
sql = values.to_crewait_sql

while !sql.empty? do
query_string = "insert into #{model_class} (#{keys.join(', ')}) values #{sql.shift}"
while !sql.empty? && (query_string.length + sql.last.length < 999_999) do
query_string << ',' << sql.shift
end
ActiveRecord::Base.connection.execute(query_string)
end
while !sql.empty? do
query_string = "insert into #{model_table} (#{keys.join(', ')}) values #{sql.shift}"
while !sql.empty? && (query_string.length + sql.last.length < 999_999) do
query_string << ',' << sql.shift
end
# Doesn't work with multiple connections, use model's connection instead ...Dan
#ActiveRecord::Base.connection.execute(query_string)
model_class.connection.execute(query_string)
end
end
# this was originally called "<<", but changed for namespacing
def respectively_insert(other_hash)
Expand Down