DBIx-Lite
view release on metacpan or search on metacpan
lib/DBIx/Lite/ResultSet.pm view on Meta::CPAN
if (my $pk = $self->{table}->autopk) {
$insert_cols = clone $insert_cols;
$insert_cols->{$pk} = $self->{dbix_lite}->_autopk($self->{table}{name})
if !exists $insert_cols->{$pk};
}
# return a DBIx::Lite::Row object with the inserted values
return $self->_inflate_row($insert_cols);
}
sub update_sql {
my $self = shift;
my $update_cols = shift;
ref $update_cols eq 'HASH' or croak "update_sql() requires a hashref";
my $update_where = { -and => $self->{where} };
if ($self->{cur_table}{name} ne $self->{table}{name}) {
my @pk = $self->{cur_table}->pk
or croak "No primary key defined for " . $self->{cur_table}{name} . "; cannot update using relationships";
@pk == 1
lib/DBIx/Lite/ResultSet.pm view on Meta::CPAN
};
}
return $self->{dbix_lite}->{abstract}->update(
-table => $self->_table_alias_expr($self->{cur_table}{name}, 'update'),
-set => $update_cols,
-where => $update_where,
);
}
sub update_sth {
my $self = shift;
my $update_cols = shift;
ref $update_cols eq 'HASH' or croak "update_sth() requires a hashref";
my ($sql, @bind) = $self->update_sql($update_cols);
return $self->{dbix_lite}->dbh->prepare($sql) || undef, @bind;
}
sub update {
my $self = shift;
my $update_cols = shift;
ref $update_cols eq 'HASH' or croak "update() requires a hashref";
my $affected_rows;
$self->{dbix_lite}->dbh_do(sub {
my ($sth, @bind) = $self->update_sth($update_cols);
$affected_rows = $sth->execute(@bind);
});
return $affected_rows;
lib/DBIx/Lite/Row.pm view on Meta::CPAN
sub __dbix_lite_row_storage { $_[0] }
sub hashref {
my $self = shift;
my $selfs = $self->__dbix_lite_row_storage;
return clone $selfs->{data};
}
sub update {
my $self = shift;
my $update_cols = shift or croak "update() requires a hashref";
my $selfs = $self->__dbix_lite_row_storage;
$selfs->{dbix_lite}->table($selfs->{table}{name})->search($self->_pk)->update($update_cols);
$selfs->{data}{$_} = $update_cols->{$_} for keys %$update_cols;
$self;
}
sub delete {
( run in 0.256 second using v1.01-cache-2.11-cpan-4d4bc49f3ae )