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



26
27
28
# File 'app/controllers/postgresql_lo_streamer/lo_controller.rb', line 26

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

#streamObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/postgresql_lo_streamer/lo_controller.rb', line 5

def stream
  send_file_headers! configuration.options

  object_identifier = params[:id].to_i
  if !object_exists?(object_identifier)
    self.status = 404
    render :nothing => true and return
  end

  self.status = 200
  self.response_body = 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