perl icon

Rose::DB::Object - aggregates

Posted in , , Thu, 01 Jun 2006 00:29:00 GMT

One of the advantages DBIx::Class has over Rose::DB::Object (RDBO) is that it natively handles GROUP BY, HAVING, etc. I use GROUP BY a lot so I asked John Siracusa how to do aggregate functions such as count and sum using GROUP BY with RDBO.

RDBO doesn't have native support for aggregates because it's designed to return row objects and the results of aggregate functions are not rows in any table. In the future RDBO may have a built-in get_results() Manager method that returns "data" instead of row objects, but for now there are two alternatives (quotes by Siracusa):

  1. Manager methods: "the RDBO way to do queries that have aggregates is to create a manager method that runs the desired query and returns the results. you can use the RDBO query builder to constrict the SQL if you want, the where part, for example"
  2. Views: "the other way is to make a view and have RDBO front that view as if it were a table letting the db do the aggregating part under the covers [...] big aggregate queries tend to be slow vs. a good view in a database that supports them well" - aggregates digg:Rose::DB::Object - aggregates reddit:Rose::DB::Object - aggregates spurl:Rose::DB::Object - aggregates wists:Rose::DB::Object - aggregates simpy:Rose::DB::Object - aggregates newsvine:Rose::DB::Object - aggregates blinklist:Rose::DB::Object - aggregates furl:Rose::DB::Object - aggregates fark:Rose::DB::Object - aggregates blogmarks:Rose::DB::Object - aggregates Y!:Rose::DB::Object - aggregates smarking:Rose::DB::Object - aggregates magnolia:Rose::DB::Object - aggregates segnalo:Rose::DB::Object - aggregates

no comments

catalyst iconperl icontemplatetoolkit icon

Catalyst::View::TT 0.23 - render method

Posted in , , Wed, 31 May 2006 23:54:00 GMT

Catalyst::View::TT 0.23, the Template Toolkit View for the Catalyst MVC framework, was recently released on May 27, 2006 and just in time. It breaks out the render functionality as a separate method from the process method allowing direct rendering of TT templates in addition to handling the overall catalyst response. This is useful when you want to render a template for say an email body or fragments in a JSON response. The render method is accessed as follows:

my $output = $c->view('TT')->render(
    $c, '', \%args

Prior to this, Catalyst::Plugin::SubRequest was the recommended way for rendering a TT template when C::V::TT was being used, e.g. the email body example in the SubRequest POD. This method is a kludge because SubRequest is designed to make public action requests, not for just rendering a template. I didn't mind using SubRequest just once to render a TT template for email, however I grew concerned when I starting using it multiple times to render HTML fragments to return via JSON. I was converting more private methods to public actions just so they could be called by SubRequest when I decided this was too kludgy and went to see if I could call TT directly. I went code diving in C::V::TT where I found the render method in 0.23 on I had to install 0.23 from the tarball directly since my CPAN shell would only give me 0.22.

SubRequest also seems to have a problem in that it nukes the Catalyst::Request parameters so $c->req->params is no longer populated correctly after a $c->subreq call. This created strange results without errors that were hard to pinpoint for me. On #catalyst, network_ninja mentioned he got around this problem by copying the params to $c->req->parameters and giving that to SubRequest. My solution is to just stop using SubRequest, at least when I only want to render a template.

Thanks to the Cat team for breaking out render and releasing it just when I went looking for it. 0.23 - render method digg:Catalyst::View::TT 0.23 - render method reddit:Catalyst::View::TT 0.23 - render method spurl:Catalyst::View::TT 0.23 - render method wists:Catalyst::View::TT 0.23 - render method simpy:Catalyst::View::TT 0.23 - render method newsvine:Catalyst::View::TT 0.23 - render method blinklist:Catalyst::View::TT 0.23 - render method furl:Catalyst::View::TT 0.23 - render method fark:Catalyst::View::TT 0.23 - render method blogmarks:Catalyst::View::TT 0.23 - render method Y!:Catalyst::View::TT 0.23 - render method smarking:Catalyst::View::TT 0.23 - render method magnolia:Catalyst::View::TT 0.23 - render method segnalo:Catalyst::View::TT 0.23 - render method

1 comment

Older posts: 1 2 3