Skip to content

Commit

Permalink
column value update by setter method
Browse files Browse the repository at this point in the history
  • Loading branch information
yappo committed Oct 2, 2012
1 parent 6f5d957 commit 47c5760
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/Teng.pm
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ in your script.
id => 1,
}
);
$row->update({name => 'nekokak'});
$row->update({name => 'nekokak'}); # same do { $row->name('nekokak'); $row->update; }
$row = $teng->search_by_sql(q{SELECT id, name FROM user WHERE id = ?}, [ 1 ]);
$row->delete();
Expand Down Expand Up @@ -817,6 +817,18 @@ You can also call update on a row object:
my $row = $teng->single('user',{id => 1});
$row->update({name => 'nomaneko'});
You can use the set_column method:
my $row = $teng->single('user', {id => 1});
$row->set_column( name => 'yappo' );
$row->update;
you can column update by using column method:
my $row = $teng->single('user', {id => 1});
$row->name('yappo');
$row->update;
=item $delete_row_count = $teng->delete($table, \%delete_condition)
Deletes the specified record(s) from C<$table> and returns the number of rows deleted. You may optionally specify C<%delete_condition> to create a conditional delete query.
Expand Down
2 changes: 2 additions & 0 deletions lib/Teng/Row.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ sub _lazy_get_data {
return sub {
my $self = shift;

return $self->set_column( $col => @_ ) if @_;

# "Untrusted" means the row is set_column by scalarref.
# e.g.
# $row->set_column("date" => \"DATE()");
Expand Down
16 changes: 16 additions & 0 deletions t/002_common/002_update.t
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,21 @@ subtest 'empty update' => sub {
is $row->name, 'perl';
};

subtest 'update by setter column' => sub {
my $row = $db->single('mock_basic',{
id => 1,
});
is $row->name, 'perl';

$row->name('tora');
is $row->update, 1;
is $row->name, 'tora';

my $row2 = $db->single('mock_basic',{
id => 1,
});
is $row2->name, 'tora';
};

done_testing;

0 comments on commit 47c5760

Please sign in to comment.