Permalink
Browse files

[Squerl] can return rows for arbitrary SQL

  • Loading branch information...
1 parent 5cddf99 commit f2b110dd44e160ac843c314712aca214bd02a42f @masak committed Sep 23, 2009
Showing with 13 additions and 1 deletion.
  1. +8 −1 lib/Squerl.pm
  2. +5 −0 t/squerl/02-dataset.t
View
9 lib/Squerl.pm
@@ -114,7 +114,14 @@ class Squerl::Dataset does Positional {
$name;
}
+ method static_sql($sql) {
+ $sql
+ }
+
method select_sql() {
+ return self.static_sql(%!opts<sql>)
+ if %!opts.exists('sql');
+
# RAKUDO: Real string interpolation
"SELECT * FROM {%!opts<from>}"
~ (%!opts.exists('filter')
@@ -168,7 +175,7 @@ class Squerl::Dataset does Positional {
method update_sql(*%nameds) {
my $values = join $COMMA_SEPARATOR, map {
- "{.key} = {self.literal(.value)}"
+ "{.key} = {self.literal(.value)}"
}, %nameds.pairs;
"UPDATE {%!opts<from>} SET $values";
}
View
5 t/squerl/02-dataset.t
@@ -251,4 +251,9 @@ role R2 { method values { {} } }
'format an update statement';
}
+{
+ is $dataset.clone(:sql('xxx yyy zzz')).select_sql(), 'xxx yyy zzz',
+ 'return rows for arbitrary SQL';
+}
+
done_testing;

0 comments on commit f2b110d

Please sign in to comment.