From: Matt S Trout Date: Sun, 13 Oct 2019 04:24:43 +0000 (+0000) Subject: passthrough role for DBIC sqlmaker X-Git-Tag: v1.90_03~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c509b481a9f43fad4b6dd8ff0a2944e879aceb46;p=dbsrgits%2FSQL-Abstract.git passthrough role for DBIC sqlmaker --- diff --git a/lib/DBIx/Class/SQLMaker/Role/SQLA2Passthrough.pm b/lib/DBIx/Class/SQLMaker/Role/SQLA2Passthrough.pm new file mode 100644 index 0000000..39e3a56 --- /dev/null +++ b/lib/DBIx/Class/SQLMaker/Role/SQLA2Passthrough.pm @@ -0,0 +1,32 @@ +package DBIx::Class::SQLMaker::Role::SQLA2Passthrough; + +use Role::Tiny; + +around select => sub { + my ($orig, $self, $table, $fields, $where, $rs_attrs, $limit, $offset) = @_; + + $fields = \[ $self->render_expr({ -list => [ + grep defined, + map +(ref($_) eq 'HASH' + ? do { + my %f = %$_; + my $as = delete $f{-as}; + my ($f, $rhs) = %f; + my $func = +{ "-${f}" => $rhs }; + ($as + ? +{ -op => [ 'as', $func, { -ident => [ $as ] } ] } + : $func) + } + : $_), ref($fields) eq 'ARRAY' ? @$fields : $fields + ] }, -ident) ]; + + if (my $gb = $rs_attrs->{group_by}) { + $rs_attrs = { + %$rs_attrs, + group_by => \[ $self->render_expr({ -list => $gb }, -ident) ] + }; + } + $self->$orig($table, $fields, $where, $rs_attrs, $limit, $offset); +}); + +1;