DBIx-QuickORM
view release on metacpan or search on metacpan
worktrees/dbic-compat-native-features/lib/DBIx/QuickORM/Row.pm view on Meta::CPAN
example:
my $result = $row->cas('version', {version => $row->field('version') + 1});
See the C<cas> method in L<DBIx::QuickORM::Handle> for the full description.
=back
=cut
sub force_sync {
my $self = shift;
delete $self->row_data->{+DESYNC};
return $self;
}
# Fetch new data from the db
sub refresh {
my $self = shift;
$self->check_pk;
croak "This row is not in the database yet" unless $self->is_stored;
my $row = $self->connection->handle($self)->one;
return $row if $row;
$self->connection->state_invalidate(source => $self->source, row => $self, reason => "row no longer exists in the database");
croak "Cannot refresh: this row no longer exists in the database";
}
# Remove pending changes (and clear desync)
sub discard {
my $self = shift;
delete $self->row_data->{+DESYNC};
delete $self->row_data->{+PENDING};
return $self;
}
sub delete {
my $self = shift;
$self->check_pk;
croak "This row is not in the database yet" unless $self->is_stored;
return $self->connection->handle($self)->delete;
}
sub cas {
my $self = shift;
my ($input, $changes) = @_;
$self->check_pk;
croak "This row is not in the database yet" unless $self->is_stored;
return $self->connection->handle($self)->cas($input, $changes);
}
sub update {
my $self = shift;
my $changes;
if (@_ == 1) {
($changes) = @_;
}
else {
$changes = {@_};
}
$self->check_pk;
my $source = $self->source;
for my $field (keys %$changes) {
croak "This row does not have a '$field' field" unless $source->has_field($field);
croak "Cannot set field '$field': it is a database-generated column"
if $source->field_is_generated($field);
}
$self->_check_stale;
# Stage the changes against the current transaction so a rollback
# discards them along with the transaction's frame.
$self->{+ROW_DATA}->change_state({TRANSACTION() => $self->connection->current_txn, PENDING() => {%$changes}});
my $row_data = $self->row_data;
if (my $desync = $row_data->{+DESYNC}) {
delete $desync->{$_} for keys %$changes;
delete $row_data->{+DESYNC} unless keys %$desync;
}
$self->save();
return $self;
}
############################
# }}} Manipulation Methods #
############################
#####################
# {{{ Field methods #
#####################
=pod
=over 4
=item $val = $row->field($name)
=item $row->field($name => $value)
=item $val = $row->raw_field($name)
Get (or, with a value, set) a single field. C<field> returns the inflated
value; C<raw_field> returns the deflated/raw value.
Setting a field stages the change against the current transaction (when one
is open), so rolling back that transaction or savepoint discards the staged
change.
( run in 1.043 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )