Permalink
Browse files

[Squerl] can select from several tables

  • Loading branch information...
1 parent 97aa3ee commit 333c29e31182f9f41fd6e4fb0d20d3a3b3b8a397 @masak committed Sep 24, 2009
Showing with 13 additions and 1 deletion.
  1. +8 −1 lib/Squerl.pm
  2. +5 −0 t/squerl/02-dataset.t
View
@@ -135,12 +135,19 @@ class Squerl::Dataset does Positional {
if %!opts<from> ~~ Array && %!opts<from>.elems > 1;
}
+ sub source_list(@source) {
+ die 'No source specified for query'
+ if !defined @source || !@source;
+
+ @source.join($COMMA_SEPARATOR);
+ }
+
method select_sql() {
return self.static_sql(%!opts<sql>)
if %!opts.exists('sql');
# RAKUDO: Real string interpolation
- "SELECT * FROM {%!opts<from>}"
+ "SELECT * FROM {source_list(%!opts<from>.list)}"
~ (%!opts.exists('filter')
?? " WHERE ({%!opts<filter>.fmt('%s = %s')})"
!! '');
@@ -300,4 +300,9 @@ $dataset = Squerl::Dataset.new(undef).from('t1', 't2');
'multi-table dataset dies on .insert_sql';
}
+{
+ is $dataset.select_sql, 'SELECT * FROM t1, t2',
+ 'generate a select query FROM all specified tables';
+}
+
done_testing;

0 comments on commit 333c29e

Please sign in to comment.