return 'WHERE ' . $self->_recurse_where(\@clauses);
}
- method _order_by(ArrayAST $ast) {
- my (undef, @clauses) = @$ast;
-
+ method _order_by(AST $ast) {
+ my @clauses = @{$ast->{order_by}};
+
my @output;
for (@clauses) {
- if ($_->[0] =~ /^-(asc|desc)$/) {
+ if (is_ArrayRef($_) && $_->[0] =~ /^-(asc|desc)$/) {
my $o = $1;
push @output, $self->dispatch($_->[1]) . " " . uc($o);
next;
return "ORDER BY " . join(", ", @output);
}
- method _name(ArrayAST $ast) {
- my (undef, @names) = @$ast;
+ method _name(AST $ast) {
+ my @names = @{$ast->{args}};
my $sep = $self->name_separator;
my $quote = $self->is_quoting
}
- method _list(ArrayAST $ast) {
- my (undef, @items) = @$ast;
+ method _list(AST $ast) {
+ my @items = @{$ast->{args}};
return join(
$self->list_separator,
map { $self->dispatch($_) } @items);
}
- method _alias(ArrayAST $ast) {
- my (undef, $alias, $as) = @$ast;
-
- confess "Not enough paremeters to -alias"
- unless defined $as;
-
+ method _alias(AST $ast) {
+
# TODO: Maybe we want qq{ AS "$as"} here
- return $self->dispatch($alias) . " AS $as";
+ return $self->dispatch($ast->{ident}) . " AS " . $ast->{as};
}
use strict;
use warnings;
-use Test::More tests => 11;
+use Test::More tests => 8;
use Test::Differences;
use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
my $sqla = SQL::Abstract->create(1);
# TODO: once MXMS supports %args, use that here
-is $sqla->dispatch( [ -name => qw/me id/]), "me.id",
+is $sqla->dispatch( { -type => 'name', args => [qw/me id/] }), "me.id",
"Simple name generator";
-is $sqla->dispatch( [ -name => qw/me */]),
+is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
"me.*",
"Simple name generator";
$sqla->quote_chars(['`']);
-is $sqla->dispatch( [ -name => qw/me */]),
+is $sqla->dispatch( { -type => 'name', args => [qw/me */]}),
"`me`.*",
"Simple name generator";
$sqla->disable_quoting;
is $sqla->dispatch(
- [ '-false' ]
+ { -type => 'false' }
), "0 = 1", "false value";
is $sqla->dispatch(
- [ '-true' ]
+ { -type => 'true' }
), "1 = 1", "true value";
is $sqla->dispatch(
- [ -list =>
- [ -name => qw/me id/],
- [ -name => qw/me foo bar/],
- [ -name => qw/bar/]
- ]
+ { -type => 'list',
+ args => [
+ { -type => name => args => [qw/me id/] },
+ { -type => name => args => [qw/me foo bar/] },
+ { -type => name => args => [qw/bar/] }
+ ]
+ }
), "me.id, me.foo.bar, bar",
"List generator";
is $sqla->dispatch(
- [ -alias => [ -name => qw/me id/], "foobar", ]
+ { -type => 'alias', ident => { -type => name => args => [qw/me id/]}, as => "foobar" }
), "me.id AS foobar",
"Alias generator";
-is $sqla->dispatch(
- [ -order_by => [ -name => qw/me date/ ] ]
-), "ORDER BY me.date",
- "order by";
-
-is $sqla->dispatch(
- [ -order_by =>
- [ -name => qw/me date/ ],
- [ -name => qw/me foobar/ ],
- ]
-), "ORDER BY me.date, me.foobar",
- "order by";
-
-is $sqla->dispatch(
- [ -order_by => [ -desc => [ -name => qw/me date/ ] ] ]
-), "ORDER BY me.date DESC",
- "order by desc";
-
--- /dev/null
+use strict;
+use warnings;
+
+use Test::More tests => 4;
+use Test::Differences;
+
+use_ok('SQL::Abstract') or BAIL_OUT( "$@" );
+
+my $sqla = SQL::Abstract->create(1);
+
+
+is $sqla->dispatch(
+ { -type => 'order_by', order_by => [ { -type => name => args => [qw/me date/ ] } ] }
+), "ORDER BY me.date",
+ "order by";
+
+is $sqla->dispatch(
+ { -type => 'order_by',
+ order_by => [
+ { -type => name => args => [qw/me date/] },
+ { -type => name => args => [qw/me foobar/] },
+ ]
+ }
+), "ORDER BY me.date, me.foobar",
+ "order by";
+
+# Hrmmm how to mark this up.
+is $sqla->dispatch(
+ { -type => 'order_by',
+ order_by => [
+ [ -desc => { -type => name => args => [qw/me date/ ] } ]
+ ]
+ }
+), "ORDER BY me.date DESC",
+ "order by desc";