Skip to content

Instantly share code, notes, and snippets.

@simonecesano
Created August 4, 2016 19:24
Show Gist options
  • Save simonecesano/568ed87082914c1c25fa881cdcca8bfc to your computer and use it in GitHub Desktop.
Save simonecesano/568ed87082914c1c25fa881cdcca8bfc to your computer and use it in GitHub Desktop.
use utf8;
package Mare::Schema::Result::SummaryTHing;
use strict;
use warnings;
use base 'DBIx::Class::Core';
__PACKAGE__->table_class('DBIx::Class::ResultSource::View');
__PACKAGE__->table('summary_thing');
__PACKAGE__->result_source_instance->is_virtual(1);
my $sql = <<'SQL';
select foo.thing as thing,
string_agg(distinct foo.bar, ',') as bars,
count(*) as results
from foo
join gongs_bar on gongs_foo.yak = foo.yak
left join yak_hair on yak_hair.some_field = gongs_foo.some_field
group by foo.thing
SQL
;
__PACKAGE__->add_columns(
"thing",
{ data_type => "varchar", is_nullable => 1, size => 32 },
"bars",
{ data_type => "varchar", is_nullable => 1, size => 256 },
"results",
{ data_type => "integer" },
);
__PACKAGE__->result_source_instance->view_definition($sql);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment