Updates to MX::Declare required changes
[dbsrgits/SQL-Abstract-2.0-ish.git] / lib / SQL / Abstract / AST / v1.pm
index a87fc5c..b43d479 100644 (file)
@@ -11,8 +11,6 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract {
   use SQL::Abstract::Types qw/AST/;
   use Devel::PartialDump qw/dump/;
 
-  clean;
-
   # set things that are valid in where clauses
   override _build_expr_dispatch_table {
     return { 
@@ -80,6 +78,45 @@ class SQL::Abstract::AST::v1 extends SQL::Abstract {
     return join(' ', @output);
   }
 
+  method _update(AST $ast) {
+
+    for (qw/columns values tablespec/) {
+      confess "'$_' is required in update AST with " . dump ($ast)
+        unless exists $ast->{$_};
+    }
+
+    my $table = $ast->{tablespec};
+    confess 'update: tablespec must be an ident or an alias in ' . dump($ast)
+      unless $table->{-type} =~ /^identifier|alias$/;
+
+    my @output = (
+        'UPDATE',
+        $self->dispatch($table),
+        'SET'
+    );
+
+    confess 'update: Number of values does not match columns: ' . dump($ast)
+      if @{$ast->{columns}} != @{$ast->{values}};
+    
+    my $list = {
+      -type => 'list',
+      args => [ map {
+        { -type => 'expr',
+          op => '==', # This should really be '=' but hmmmmmmmm
+          args => [
+            $ast->{columns}[$_],
+            $ast->{values}[$_]
+          ]
+        }
+      } 0..$#{$ast->{columns}} ]
+    };
+
+    push @output, $self->dispatch($list);
+      
+    return join(' ', @output);
+    
+  }
+
   method _join(HashRef $ast) {
 
     # TODO: Validate join type