Chisel Wright wrote:
Morning all,
I'm just about to embark on an exercise that's a sync of sorts from a Pg
database to a mysql database (backend app to public website).
The table(s) I'm interested in do not comprise the whole database, I'm
just pushing data (on demand) for a record and relevant join data.
The table schemas match on both sides, so no evil column mapping to
worry about.
With this in mind, I was wondering if there was some way of doing
something like the psudo-ish code below:
$record = $schema_pg->resultset('MainTable')->find($id);
$coldata_hashref = $record->MAGIC_FUNCTION();
$schema_mysql->create_or_update($coldata_hashref);
I've had a quick run through the docs for ::ResultSet and
::Manual::Cookbook but nothing leaps out as being MAGIC_FUNCTION()
A simple find() will do what you are asking for, provided that you've
set DBIx::Class::ResultClass::HashRefInflator as your result class:
my $rs = $schema_pg->resultset('MainTable');
$rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
my $hash_ref = $rs->find($id);
$schema_mysql->create_or_update($hash_ref);
http://search.cpan.org/~jrobinson/DBIx-Class-0.08009/lib/DBIx/Class/Manual/Cookbook.pod#Skip_object_creation_for_faster_results
This is more efficient than a map() on the returned row object, since it
skips the object creation altogether.
Cheers,
Emanuele.
P.S.
There is bug that emerges in certain cases (not in the code shown above
anyway), for which a patch is arriving ;-)
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[EMAIL PROTECTED]