Class: PostgresqlLoStreamer::Streamer
- Inherits:
-
Object
- Object
- PostgresqlLoStreamer::Streamer
- Defined in:
- lib/postgresql_lo_streamer/streamer.rb
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#object_identifier ⇒ Object
Returns the value of attribute object_identifier.
Instance Method Summary collapse
-
#initialize(connection, object_identifier) ⇒ Streamer
constructor
A new instance of Streamer.
- #object_exists? ⇒ Boolean
- #stream ⇒ Object
Constructor Details
#initialize(connection, object_identifier) ⇒ Streamer
Returns a new instance of Streamer.
4 5 6 7 |
# File 'lib/postgresql_lo_streamer/streamer.rb', line 4 def initialize(connection, object_identifier) @connection = connection @object_identifier = object_identifier end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
2 3 4 |
# File 'lib/postgresql_lo_streamer/streamer.rb', line 2 def connection @connection end |
#object_identifier ⇒ Object
Returns the value of attribute object_identifier.
2 3 4 |
# File 'lib/postgresql_lo_streamer/streamer.rb', line 2 def object_identifier @object_identifier end |
Instance Method Details
#object_exists? ⇒ Boolean
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/postgresql_lo_streamer/streamer.rb', line 9 def object_exists? begin @connection.lo_open(@object_identifier, ::PG::INV_READ) rescue PG::Error => e if e.to_s.include? "does not exist" return false end raise end return true end |
#stream ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/postgresql_lo_streamer/streamer.rb', line 21 def stream return Enumerator.new do |y| @connection.transaction do lo = @connection.lo_open(@object_identifier, ::PG::INV_READ) while data = connection.lo_read(lo, 4096) do y << data end @connection.lo_close(lo) end end end |