class RailsRedshiftReplicator::Adapters::PostgreSQL
Public Instance Methods
connection()
click to toggle source
# File lib/rails_redshift_replicator/adapters/postgresql.rb, line 12 def connection @connection ||= @ar_client.instance_variable_get("@connection") end
last_record_query_command(sql)
click to toggle source
@see RailsRedshiftReplicator::Adapters::Generic#last_record_query_command
# File lib/rails_redshift_replicator/adapters/postgresql.rb, line 17 def last_record_query_command(sql) @ar_client.exec_query(sql).first['_last_record'] end
query_command(sql)
click to toggle source
Executes query in stream mode to optimize memory usage, using pg driver. @param sql [String] sql to execute
# File lib/rails_redshift_replicator/adapters/postgresql.rb, line 7 def query_command(sql) connection.send_query(sql) connection.set_single_row_mode end
write(file_path, query_result)
click to toggle source
Writes query results to a file @param file_path [String] path to output @param query_result [#get_result] Resultset from the query_command
@return [Integer] number of records
# File lib/rails_redshift_replicator/adapters/postgresql.rb, line 25 def write(file_path, query_result) line_number = 0 CSV.open(file_path, "w") do |csv| query_result.get_result.stream_each do |row| csv << row.map{ |_,field| field.is_a?(String) ? field.gsub("\n", " ") : field } line_number+=1 end end line_number end