NAME

Pg::Blobs - Blobs management methods for Postgresql related DB modules.

SYNOPSIS

This is a Moose::Role. Consume it in your DB management class and implement the method pgblobs_dbh.

Note that blob management in postgresql do not work outside a transaction.

Blobs are just numeric OIDs in postgresql. You will have to store them in a classic OID table column for later retrieval.

Example:

package My::DB;
use Moose;
with qw/Pg::Blobs/;

sub pgblobs_dbh{ .. return the dbh connection of your choice ..}
...

package main;
my $db = .. an instance of My::DB ..;

#### IMPORTANT: IN A TRANSACTION
my $blob = $db->pgblobs_store_blob('binary content');
my $content = $db->pgblobs_fetch_blob($blob);
etc..

pgblobs_create_blob

Creates a Postgresql empty blob (oid) and returns it.

Note that it is not very useful. Use pgblobs_stream_in_blob or pgblobs_store_blob instead.

Usage:

my $blob = $this->pgblobs_create_blob()

pgblobs_store_blob ($buf)

Stores the given binary content in the postgresql db and return the blob id.

Usage:

my $blob = $this->pgblobs_store_blob('Full short binary content');

pgblobs_stream_in_blob ($sub)

Pulls data using the given read code, storing it into a new blob.

Returns the new blob id.

Usage:

my $blob = $this->pgblobs_stream_in_blob(sub{ return 'Next slice of bytes or undef' ;});

pgblobs_stream_out_blob

Streams out the given blob ID in the given write sub and return the number of bytes retrieved.

Example:

$s->stream_out_blob(sub{ my $fresh_bytes = shift ; ... ; } , $oid );

pgblobs_fetch_blob ($oid)

Fectches the blob binary content in one go

Usage:

my $small_content = $this->pgblobs_fetch_blob($blob);