}
sub _render_value {
- defined($_[1]->{value})
- ? [ '?', $_[1] ]
- : [ 'NULL' ];
+ [ '?', $_[1] ]
}
sub _operator_type { 'SQL.Naive' }
sub _render_update {
my ($self, $dq) = @_;
my ($target, $set, $where) = @{$dq}{qw(target set where)};
+ unless ($set) {
+ die "Must have set key - names+value keys not yet tested";
+ my ($names, $value) = @{$dq}{qw(names value)};
+ die "Must have names and value or set" unless $names and $value;
+ die "names and value must be same size" unless @$names == @$value;
+ $set = [ map [ $names->[$_], $value->[$_] ], 0..$#$names ];
+ }
my @rendered_set = intersperse(
',', map [ intersperse('=', map $self->_render($_), @$_) ], @{$set}
);
];
}
+sub _render_insert {
+ my ($self, $dq) = @_;
+ my ($target, $names, $values, $returning)
+ = @{$dq}{qw(target names values returning)};
+ unless ($values) {
+ die "Must have values key - sets key not yet implemented";
+ }
+ [ $self->_format_keyword('INSERT INTO'),
+ $self->_render($target),
+ ($names
+ ? ('(', intersperse(',', map $self->_render($_), @$names), ')')
+ : ()),
+ $self->_format_keyword('VALUES'),
+ intersperse(',',
+ map [ '(', intersperse(',', map $self->_render($_), @$_), ')' ],
+ @$values
+ ),
+ ($returning
+ ? ($self->_format_keyword('RETURNING'),
+ intersperse(',', map $self->_render($_), @$returning))
+ : ()),
+ ];
+}
+
1;