Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for multiple databases #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions lib/crewait.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def self.config(hash)

module BaseMethods
def next_insert_id
connection = ActiveRecord::Base.connection
connection = self.connection
database, adapter = connection.current_database, connection.adapter_name
sql = case adapter.downcase
when 'postgresql'
Expand All @@ -55,7 +55,7 @@ def next_insert_id
else
raise "your database/adapter (#{adapter}) is not supported by crewait! want to write a patch?"
end
results = ActiveRecord::Base.connection.execute(sql)
results = connection.execute(sql)
case adapter.downcase
when 'postgresql'
results[0]["nextval"].to_i
Expand All @@ -76,7 +76,7 @@ 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
end
keys = self.keys
values = []
Expand All @@ -87,11 +87,11 @@ def import_to_sql(model_class)
sql = values.to_crewait_sql

while !sql.empty? do
query_string = "insert into #{model_class} (#{keys.join(', ')}) values #{sql.shift}"
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
ActiveRecord::Base.connection.execute(query_string)
model_class.connection.execute(query_string)
end
end
# this was originally called "<<", but changed for namespacing
Expand Down