Created
July 7, 2011 19:13
-
-
Save ktat/1070298 to your computer and use it in GitHub Desktop.
SQL::Maker の $where/$opt の処理が別メソッドだったら
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sub search { | |
my ($self, $table_name, $where, $opt) = @_; | |
my $table = $self->schema->get_table( $table_name ); | |
if (! $table) { | |
Carp::croak("No such table $table_name"); | |
} | |
my $sql_maker = $self->sql_builder; | |
my $stmt = $sql_maker->new_select(select => $opt->{columns} || $table->columns); | |
if ($opt->{join}) { | |
$stmt->add_join($table_name => $opt->{join}); | |
} else { | |
$stmt->add_from($table_name); | |
} | |
# このあたりが嬉しい | |
$sql_maker->_process_where($stmt, $where); | |
$sql_maker->_process_option($stmt, $opt); | |
my $sql = $stmt->as_sql(); | |
my @binds = $stmt->bind(); | |
$self->search_by_sql($sql, \@binds, $table_name); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment