Sha256: 417d9542437088f71c7aabc2b26268304f767ee1f462e3b6dd376b736b78d15d

Contents?: true

Size: 833 Bytes

Versions: 75

Compression:

Stored size: 833 Bytes

Contents

#!/usr/bin/env ruby

require 'pg'
require 'stringio'

# Using COPY asynchronously

$stderr.puts "Opening database connection ..."
conn = PG.connect( :dbname => 'test' )
conn.setnonblocking( true )

socket = conn.socket_io

$stderr.puts "Running COPY command ..."
buf = ''
conn.transaction do
	conn.send_query( "COPY logs TO STDOUT WITH csv" )
	buf = nil

	# #get_copy_data returns a row if there's a whole one to return, false
	# if there isn't one but the COPY is still running, or nil when it's
	# finished.
	begin
		$stderr.puts "COPY loop"
		conn.consume_input
		while conn.is_busy
			$stderr.puts "  ready loop"
			select( [socket], nil, nil, 5.0 ) or
				raise "Timeout (5s) waiting for query response."
			conn.consume_input
		end

		buf = conn.get_copy_data
		$stdout.puts( buf ) if buf
	end until buf.nil?
end

conn.finish

Version data entries

75 entries across 75 versions & 6 rubygems

Version Path
jruby-pg-0.1-java sample/async_copyto.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/pg-0.20.0/sample/async_copyto.rb
pg-0.20.0-x86-mingw32 sample/async_copyto.rb
pg-0.20.0-x64-mingw32 sample/async_copyto.rb
pg-0.20.0 sample/async_copyto.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/pg-0.19.0/sample/async_copyto.rb
pg-0.19.1.pre20170124220800-x64-mingw32 sample/async_copyto.rb
pg-0.19.1.pre20170124220800-x86-mingw32 sample/async_copyto.rb
pg-0.19.1.pre20170124220800 sample/async_copyto.rb
pg-0.19.1.pre20170115074000-x64-mingw32 sample/async_copyto.rb
pg-0.19.1.pre20170115074000-x86-mingw32 sample/async_copyto.rb
pg-0.19.1.pre20170115074000 sample/async_copyto.rb
pg-0.19.0.pre20170115074000 sample/async_copyto.rb
pg-0.19.0-x86-mingw32 sample/async_copyto.rb
pg-0.19.0-x64-mingw32 sample/async_copyto.rb
pg-0.19.0 sample/async_copyto.rb
pg-0.19.0.pre20160904200247-x86-mingw32 sample/async_copyto.rb
pg-0.19.0.pre20160904200247-x64-mingw32 sample/async_copyto.rb
pg-0.19.0.pre20160904200247 sample/async_copyto.rb
pg-0.19.0.pre20160820113039-x86-mingw32 sample/async_copyto.rb