Module: CarrierWave::Storage::Adapters::PGConnection

Included in:
PostgresqlLo::File
Defined in:
lib/carrierwave/storage/adapters/pg_connection.rb

Instance Method Summary collapse

Instance Method Details

#deleteObject



29
30
31
# File 'lib/carrierwave/storage/adapters/pg_connection.rb', line 29

def delete
  connection.lo_unlink(identifier)
end

#file_lengthObject



33
34
35
36
37
38
39
40
# File 'lib/carrierwave/storage/adapters/pg_connection.rb', line 33

def file_length
  @uploader.model.transaction do
    lo = connection.lo_open(identifier)
    size = connection.lo_lseek(lo, 0, 2)
    connection.lo_close(lo)
    size
  end
end

#identifierObject



6
7
8
# File 'lib/carrierwave/storage/adapters/pg_connection.rb', line 6

def identifier
  @oid ||= connection.lo_creat
end

#readObject



10
11
12
13
14
15
16
17
# File 'lib/carrierwave/storage/adapters/pg_connection.rb', line 10

def read
  @uploader.model.transaction do
    lo = connection.lo_open(identifier)
    content = connection.lo_read(lo, file_length)
    connection.lo_close(lo)
    content
  end
end

#write(file) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/carrierwave/storage/adapters/pg_connection.rb', line 19

def write(file)
  @uploader.model.transaction do
    lo = connection.lo_open(identifier, ::PG::INV_WRITE)
    connection.lo_truncate(lo, 0)
    size = connection.lo_write(lo, file.read)
    connection.lo_close(lo)
    size
  end
end