Class: PostgresqlLoStreamer::LoController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
app/controllers/postgresql_lo_streamer/lo_controller.rb

Instance Method Summary collapse

Instance Method Details

#connectionObject



19
20
21
# File 'app/controllers/postgresql_lo_streamer/lo_controller.rb', line 19

def connection
  @con ||= ActiveRecord::Base.connection.raw_connection
end

#streamObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/postgresql_lo_streamer/lo_controller.rb', line 5

def stream
  send_file_headers! configuration.options
  self.status = 200
  self.response_body = Enumerator.new do |y|
    connection.transaction do
      lo = connection.lo_open(params[:id].to_i, ::PG::INV_READ)
      while data = connection.lo_read(lo, 4096) do
        y << data
      end
      connection.lo_close(lo)
    end
  end
end