From: Matt S Trout Date: Thu, 25 Apr 2019 14:06:36 +0000 (+0000) Subject: First attempt at SQLA2Support X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=scpubgit%2FQ-Branch.git;a=commitdiff_plain;h=5d4463f6e61ba46ff9755d2104bd1e33a8924300 First attempt at SQLA2Support --- diff --git a/lib/DBIx/Class/SQLMaker/SQLA2Support.pm b/lib/DBIx/Class/SQLMaker/SQLA2Support.pm new file mode 100644 index 0000000..c35bda9 --- /dev/null +++ b/lib/DBIx/Class/SQLMaker/SQLA2Support.pm @@ -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; diff --git a/lib/SQL/Abstract/Clauses.pm b/lib/SQL/Abstract/Clauses.pm index 78ec300..74bb20e 100644 --- a/lib/SQL/Abstract/Clauses.pm +++ b/lib/SQL/Abstract/Clauses.pm @@ -63,6 +63,21 @@ sub register_defaults { $self->{expand}{exists} = sub { $_[0]->_expand_op(undef, [ exists => $_[2] ]); }; + + # check for overriden methods + if ($self->can('_table') ne SQL::Abstract->can('_table')) { + $self->{expand_clause}{'select.from'} = sub { + return +{ -literal => [ $_[0]->_table($_[2]) ] }; + }; + } + if ($self->can('_order_by') ne SQL::Abstract->can('_order_by')) { + $self->{expand_clause}{'select.order_by'} = sub { + my ($osql, @obind) = $_[0]->_order_by($_[2]); + $osql =~ s/^order by //i; + return undef unless length($osql); + return +{ -literal => [ $osql, @obind ] }; + }; + } return $self; } @@ -212,7 +227,6 @@ sub render_statement { sub select { my ($self, @args) = @_; - my $stmt = do { if (ref(my $sel = $args[0]) eq 'HASH') { $sel diff --git a/lib/with.pm b/lib/with.pm index 28055b4..96c2a66 100644 --- a/lib/with.pm +++ b/lib/with.pm @@ -18,8 +18,9 @@ sub components { Class::C3::Componentised->ensure_class_loaded($_) for @comp_classes; Class::C3::Componentised->inject_base( $new_class, - @comp_classes, $class, + @comp_classes, $class ); + mro::set_mro($new_class, 'c3'); return $new_class unless ref($inv); return bless($inv, $new_class); }