Sha256: c4579e5babf6cdc605f02de421be6b9319458afbd42987e6e5d81a0c93984356

Contents?: true

Size: 863 Bytes

Versions: 1

Compression:

Stored size: 863 Bytes

Contents

require 'open3'

class MySqlStreamer

	def initialize(query, target)
		@query = query
		@name = target
	end

	def each
		puts "Using the Streaming MySQL from the command line"
		keys = nil
		connection_configuration = ETL::Base.configurations[@name.to_s]
		mysql_command = """mysql --quick -h #{connection_configuration["host"]} -u #{connection_configuration["username"]} -e \"#{@query.gsub("\n","")}\" -D #{connection_configuration["database"]} --password=#{connection_configuration["password"]} -B"""
		Open3.popen3(mysql_command) do |stdin, out, err, external|
			until (line = out.gets).nil? do
				line = line.gsub("\n","")
				if keys.nil?
					keys = line.split("\t")
				else
					hash = Hash[keys.zip(line.split("\t"))]
					yield hash
				end
			end
			error = err.gets
			if (!error.nil? && error.strip.length > 0)
				throw error
			end
		end
	end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activewarehouse-etl-1.0.0.rc1 lib/etl/control/source/mysql_streamer.rb