[Dbix-class] A strategy for pivots

dorian taylor dorian.taylor.lists at gmail.com
Tue Mar 22 04:58:54 GMT 2011


Hi all,

I have a database containing number of different entities for which I
want to basically do the same thing: make pretty pictures.

I am making a pipeline that more or less goes like this: Result set ->
pivot table -> bar charts/time series/etc.

It makes sense to me to consolidate the pivot function into a single
ResultSet superclass so I can use it among various entity-specific
ResultSets. A pivot, of course, is (at least the definition I care
about) when an aggregate is grouped by two columns, the unique values
in the second of which become the second through last columns to form
a 2-dimensional matrix, whose cells are populated by the aggregate. I
then plan take the output of this function and pass it directly into
some kind of formatter (e.g. CSV, JSON, whatever) and then into
something which can render a chart. Some questions:

1) Is there already a ResultSet superclass (or reasonable facsimile)
that does this pivot (that apparently eludes my search-fu)?
2) If not, is this a totally insane strategy?
3) If not, would it make sense to generalize this functionality?

And a bonus question:

4) Does it make sense to fake up a ResultSet to keep with the
interface, or produce a different structure (e.g. Data::Table, which
already has a pivot method)?

Thanks,

-- 
Dorian Taylor
http://doriantaylor.com/



More information about the DBIx-Class mailing list