Teng::Row - Teng's Row class
- $row = Teng::Row->new
- create new Teng::Row's instance
- $row->get($col)
-
my $val = $row->get($column_name);
# alias
my $val = $row->$column_name;
get a column value from a row object.
Note: This method inflates values.
- $row->set($col, $val)
-
$row->set($col => $val);
set column data.
Note: This method deflates values.
- $row->get_column($column_name)
-
my $val = $row->get_column($column_name);
get a column value from a row object.
Note: This method does not inflate values.
- $row->get_columns
-
my $data = $row->get_columns;
Does "get_column", for all
column values.
Note: This method does not inflate values.
- $row->set_columns(\%new_row_data)
-
$row->set_columns({$col => $val});
set columns data.
Note: This method does not deflate values.
- $row->set_column($col => $val)
-
$row->set_column($col => $val);
# alias
$row->$col($val);
set column data.
Note: This method does not deflate values.
- $row->get_dirty_columns
- returns those that have been changed.
- $row->is_changed
- returns true, If the row object have a updated column.
- $row->update([$arg : HashRef, $where : HashRef])
- update is executed for instance record.
It works by schema in which primary key exists.
$row->update({name => 'tokuhirom'});
# or
$row->set({name => 'tokuhirom'});
$row->update;
If $arg is supplied, each pairs are
passed to "set()" method before
update.
If $where is supplied, each pairs to
be merged into default (primary keys) WHERE condition. It is useful for
optimistic lock.
$row = $teng->single(table_name, {id => 1});
$result = $row->update({point => 2}, {point => 1});
# UPDATE table_name SET point = 2 WHERE id = 1 AND point = 1;
- $row->delete
- delete is executed for instance record.
It works by schema in which primary key exists.
- my $refetched_row = $row->refetch([$opt:HashRef]);
- refetch record from database. get new row object.
You can specify $opt like
"{ for_update => 1}" optionally,
which is used to build query.
- $row->handle
- get Teng object.
$row->handle->single('table', {id => 1});
Teng::Row has methods that have name from column name. For example, if a table
has column named 'foo', Teng::Row instance of it has method 'foo'.
This method has different behave for setter or getter as
following:
# (getter) is alias of $row->get('foo')
# so this method returns inflated value.
my $inflated_value = $row->foo;
# (setter) is alias of $row->set_column('foo', $raw_value)
# so this method does not deflate the value. This only accepts raw value but inflated object.
$row->foo($raw_value);
This behave is from historical reason. You should use column name
methods with great caution, if you want to use this.