Permalink
Browse files

[Squerl] uses the :sql option for all sql methods

  • Loading branch information...
1 parent f2b110d commit ae25379dd2fd57633637743f55c8ad2ae03e8ba9 @masak committed Sep 23, 2009
Showing with 22 additions and 0 deletions.
  1. +12 −0 lib/Squerl.pm
  2. +10 −0 t/squerl/02-dataset.t
View
@@ -130,16 +130,25 @@ class Squerl::Dataset does Positional {
}
method delete_sql() {
+ return self.static_sql(%!opts<sql>)
+ if %!opts.exists('sql');
+
# RAKUDO: Real string interpolation
"DELETE FROM {%!opts<from>}";
}
method truncate_sql() {
+ return self.static_sql(%!opts<sql>)
+ if %!opts.exists('sql');
+
# RAKUDO: Real string interpolation
"TRUNCATE TABLE {%!opts<from>}";
}
method insert_sql(*@positionals, *%nameds) {
+ return self.static_sql(%!opts<sql>)
+ if %!opts.exists('sql');
+
my (@columns, @values);
for @positionals {
when Pair {
@@ -174,6 +183,9 @@ class Squerl::Dataset does Positional {
}
method update_sql(*%nameds) {
+ return self.static_sql(%!opts<sql>)
+ if %!opts.exists('sql');
+
my $values = join $COMMA_SEPARATOR, map {
"{.key} = {self.literal(.value)}"
}, %nameds.pairs;
View
@@ -256,4 +256,14 @@ role R2 { method values { {} } }
'return rows for arbitrary SQL';
}
+{
+ my $sql = 'X';
+ my $ds = Squerl::Dataset.new(undef, :$sql);
+ is $ds.select_sql(), $sql, ':sql option works for .select_sql';
+ is $ds.insert_sql(), $sql, ':sql option works for .insert_sql';
+ is $ds.delete_sql(), $sql, ':sql option works for .delete_sql';
+ is $ds.update_sql(), $sql, ':sql option works for .update_sql';
+ is $ds.truncate_sql(), $sql, ':sql option works for .truncate_sql';
+}
+
done_testing;

0 comments on commit ae25379

Please sign in to comment.