From: Brandon L. Black Date: Thu, 3 May 2007 03:03:06 +0000 (+0000) Subject: Merge 'trunk' into 'DBIx-Class-current' X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4aeeed8aba0096f1272b29d9dc794714201f232c;p=dbsrgits%2FDBIx-Class-Historic.git Merge 'trunk' into 'DBIx-Class-current' r30777@brandon-blacks-computer (orig r3224): nigel | 2007-05-02 09:58:45 -0500 Documented use of cursor->next for fast but uncomfortable data fetches r30778@brandon-blacks-computer (orig r3225): blblack | 2007-05-02 22:02:14 -0500 revert part of 3220, apparently it is breaking cloning behavior in subtle ways that we have no tests for --- 4aeeed8aba0096f1272b29d9dc794714201f232c diff --cc lib/DBIx/Class/Manual/Cookbook.pod index 369b89e,b3dff9c..4dec7ae --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@@ -1109,18 -1109,58 +1109,34 @@@ B test.p DBIx::Class is not built for speed, it's built for convenience and ease of use, but sometimes you just need to get the data, and skip the -fancy objects. Luckily this is also fairly easy using -C: - - # Define a class which just returns the results as a hashref: - package My::HashRefInflator; - - ## $me is the hashref of cols/data from the immediate resultsource - ## $prefetch is a deep hashref of all the data from the prefetched - ## related sources. - - sub mk_hash { - my ($me, $rest) = @_; - - return { %$me, - map { ($_ => mk_hash(@{$rest->{$_}})) } keys %$rest - }; - } - - sub inflate_result { - my ($self, $source, $me, $prefetch) = @_; - return mk_hash($me, $prefetch); - } - - # Change the object inflation to a hashref for just this resultset: - $rs->result_class('My::HashRefInflator'); - - my $datahashref = $rs->next; - foreach my $col (keys %$datahashref) { - if(!ref($datahashref->{$col})) { - # It's a plain value - } - elsif(ref($datahashref->{$col} eq 'HASH')) { - # It's a related value in a hashref - } - } - +fancy objects. + +To do this simply use L. + + my $rs = $schema->resultset('CD'); + + $rs->result_class('DBIx::Class::ResultClass::HashRefInflator'); + + my $hash_ref = $rs->find(1); + +Wasn't that easy? + + =head2 Get raw data for blindingly fast results + + If the C solution above is not fast enough for you, you + can use a DBIx::Class to return values exactly as they come out of the + data base with none of the convenience methods wrapped round them. + + This is used like so:- + + my $cursor = $rs->cursor + while (my @vals = $cursor->next) { + # use $val[0..n] here + } + + You will need to map the array offsets to particular columns (you can + use the I