Skip to content

Commit

Permalink
[Squerl] can select from several tables
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Sep 24, 2009
1 parent 97aa3ee commit 333c29e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/Squerl.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -135,12 +135,19 @@ class Squerl::Dataset does Positional {
if %!opts<from> ~~ Array && %!opts<from>.elems > 1; 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() { method select_sql() {
return self.static_sql(%!opts<sql>) return self.static_sql(%!opts<sql>)
if %!opts.exists('sql'); if %!opts.exists('sql');


# RAKUDO: Real string interpolation # RAKUDO: Real string interpolation
"SELECT * FROM {%!opts<from>}" "SELECT * FROM {source_list(%!opts<from>.list)}"
~ (%!opts.exists('filter') ~ (%!opts.exists('filter')
?? " WHERE ({%!opts<filter>.fmt('%s = %s')})" ?? " WHERE ({%!opts<filter>.fmt('%s = %s')})"
!! ''); !! '');
Expand Down
5 changes: 5 additions & 0 deletions t/squerl/02-dataset.t
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -300,4 +300,9 @@ $dataset = Squerl::Dataset.new(undef).from('t1', 't2');
'multi-table dataset dies on .insert_sql'; '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; done_testing;

0 comments on commit 333c29e

Please sign in to comment.