Permalink
Browse files

column value update by setter method

  • Loading branch information...
1 parent 6f5d957 commit 47c5760f2b2dfd13d9b42dbe74691bd69e5cdf08 @yappo committed Oct 2, 2012
Showing with 31 additions and 1 deletion.
  1. +13 −1 lib/Teng.pm
  2. +2 −0 lib/Teng/Row.pm
  3. +16 −0 t/002_common/002_update.t
View
@@ -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();
@@ -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.
View
@@ -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()");
View
@@ -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.