add group_by and having in ExtraClauses
Matt S Trout [Thu, 11 Apr 2019 17:49:31 +0000 (17:49 +0000)]
lib/SQL/Abstract/ExtraClauses.pm [new file with mode: 0644]

diff --git a/lib/SQL/Abstract/ExtraClauses.pm b/lib/SQL/Abstract/ExtraClauses.pm
new file mode 100644 (file)
index 0000000..9e5ddff
--- /dev/null
@@ -0,0 +1,26 @@
+package SQL::Abstract::ExtraClauses;
+
+use strict;
+use warnings;
+use if $] < '5.010', 'MRO::Compat';
+use mro 'c3';
+use base qw(SQL::Abstract::Clauses);
+
+BEGIN { *puke = \&SQL::Abstract::puke }
+
+sub new {
+  my ($proto, @args) = @_;
+  my $new = $proto->next::method(@args);
+  $new->{clauses_of}{select} = [
+    @{$new->{clauses_of}{select}}, qw(group_by having)
+  ];
+  $new->{expand_clause}{'select.group_by'} = sub {
+    $_[0]->_expand_maybe_list_expr($_[1], -ident)
+  };
+  $new->{expand_clause}{'select.having'} = sub {
+    $_[0]->expand_expr($_[1], -ident)
+  };
+  return $new;
+}
+
+1;