Pg::Blobs - Blobs management methods for Postgresql related DB modules.
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..
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()
Stores the given binary content in the postgresql db and return the blob id.
my $blob = $this->pgblobs_store_blob('Full short binary content');
Pulls data using the given read code, storing it into a new blob.
Returns the new blob id.
my $blob = $this->pgblobs_stream_in_blob(sub{ return 'Next slice of bytes or undef' ;});
Streams out the given blob ID in the given write sub and return the number of bytes retrieved.
$s->stream_out_blob(sub{ my $fresh_bytes = shift ; ... ; } , $oid );
Fectches the blob binary content in one go
my $small_content = $this->pgblobs_fetch_blob($blob);
To install Pg::Blobs, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Pg::Blobs
CPAN shell
perl -MCPAN -e shell install Pg::Blobs
For more information on module installation, please visit the detailed CPAN module installation guide.