First attempt at SQLA2Support
[scpubgit/Q-Branch.git] / lib / DBIx / Class / SQLMaker / SQLA2Support.pm
diff --git a/lib/DBIx/Class/SQLMaker/SQLA2Support.pm b/lib/DBIx/Class/SQLMaker/SQLA2Support.pm
new file mode 100644 (file)
index 0000000..c35bda9
--- /dev/null
@@ -0,0 +1,26 @@
+package DBIx::Class::SQLMaker::SQLA2Support;
+
+use strict;
+use warnings;
+use if $] < '5.010', 'MRO::Compat';
+use mro 'c3';
+use base qw(
+  DBIx::Class::SQLMaker
+  SQL::Abstract::ExtraClauses
+);
+
+sub select {
+  my $self = shift;
+  my ($sql, @bind) = $self->next::method(@_);
+  my (undef, undef, undef, $attrs) = @_;
+  if (my $with = delete $attrs->{with}) {
+    my ($wsql, @wbind) = @{ $self->render_statement({
+      -select => { with => $with }
+    }) };
+    unshift @bind, @wbind;
+    $sql = "${wsql} ${sql}";
+  }
+  return wantarray ? ($sql, @bind) : $sql;
+}
+
+1;