Hello Chris,

Am 24.08.2014 um 17:07 schrieb Chris Travers <[email protected]>:

> Hi everyone;
> 
> I am nearing completion on the logic to serialize composite types into 
> textual representation of tuples for LedgerSMB and I am wondering if there is 
> additional interest from others who use DBD::Pg.  If there is we would 
> certainly release the logic and interfaces on CPAN.  So I figured I would ask.
> 
> For those who would be interested, I guess I have a few questions:
> 
> 1.  Do you need Moose or Moo support?
> 2.  Do you need plain old hashref support?
> 3.  Do you need bytea support?
> 
> If this is unwelcome please ignore but this seemed like a good place to ask 
> since it is PostgreSQL/Perl-specific and many of you might have thought about 
> using composite types in this way.
> 
> In case it isn't clear what I am talking about is:
> 
> given a type:
> 
> CREATE TYPE foo (
>    bar text,
>    baz text
> );
> 
> and a hashref {bar => 'foo', baz => 'this, or else that'}
> 
> it should produce (foo,"this, or else that“)

I’ve done something similar a while ago but as a part of DBIx::Class  and and I 
 didn’t generalize it more than I needed  for my $work.
For each type in my database  I had a corresponding (Moose) class where every 
‚column'  was an attribute and in my BUILD method i parsed the string that came 
from the database. 

Then I wrote a   InflateColumn::PgType  plugin overwriting the register_column 
method  and so I could write : 

__PACKAGE__->load_components(qw/InflateColumn::PgType Core/);

__PACKAGE__->table('pdf_format_param');

__PACKAGE__->add_column ( bg_tpl  => { pg_type => 'PdfElement'}) ;
…

and later  access   „columns“ of PdfElement  like 

 my $bg_start = $self->sp_pdf_param->bg_tpl->start;

Worked very well for me. 
That time when I developed this, I was also thinking about making this more 
general, however  types could be nested and as Greg said, when shall the 
mapping take place.
So I decided to tell DBIx::Class which column is custom type and   to map  it 
to which class. 


Rolf Schaufelberger






        

Reply via email to