view release on metacpan or search on metacpan
lib/DBIO/Admin.pm view on Meta::CPAN
$rs ||= $self->resultset;
$set ||= $self->set;
Carp::croak('insert requires --resultset/--class and --set') unless $rs && $set;
my $resultset = $self->schema->resultset($rs);
my $obj = $resultset->new_result($set)->insert;
print ''.ref($resultset).' ID: '.join(',', $obj->id)."\n" if !$self->quiet;
return $obj;
}
sub update {
my ($self, $rs, $set, $where) = @_;
$rs ||= $self->resultset;
$set ||= $self->set;
$where ||= $self->where || {};
Carp::croak('update requires --resultset/--class and --set') unless $rs && $set;
my $resultset = $self->schema->resultset($rs)->search($where);
if (!$self->quiet) {
my $count = eval { $resultset->count };
lib/DBIO/ChangeLog.pm view on Meta::CPAN
if ($self->_changelog_is_tracked && !$self->_changelog_is_disabled) {
my %cols = $self->_changelog_filtered_columns($self->get_columns);
$self->_changelog_record('insert', \%cols);
}
return $result;
}
sub update {
my ($self, $upd) = @_;
# Apply the update values so get_dirty_columns sees them
$self->set_inflated_columns($upd) if $upd;
my %dirty = $self->get_dirty_columns;
# Filter out excluded columns
my $exclude = $self->_changelog_excluded_columns;
delete $dirty{$_} for keys %$exclude;
lib/DBIO/FilterColumn.pm view on Meta::CPAN
$self->make_column_dirty($col);
delete $self->{_column_data}{$col};
}
else {
$self->set_column($col, $self->_column_to_storage($col, $filtered));
};
return $self->{_filtered_column}{$col} = $filtered;
}
sub update {
my ($self, $data, @rest) = @_;
my $colinfos = $self->result_source->columns_info;
foreach my $col (keys %{$data||{}}) {
if ( exists $colinfos->{$col}{_filter_info} ) {
$self->set_filtered_column($col, delete $data->{$col});
# FIXME update() reaches directly into the object-hash
# and we may *not* have a filtered value there - thus
lib/DBIO/Ordered.pm view on Meta::CPAN
? $self->_next_position_value($lsib_posval)
: $self->_initial_position_value
)
);
}
return $self->next::method(@_);
}
sub update {
my $self = shift;
return $self->next::method(@_) if $self->result_source->schema->{_ORDERED_INTERNAL_UPDATE};
my $upd = shift;
$self->set_inflated_columns($upd) if $upd;
my $position_column = $self->position_column;
my @group_columns = $self->_grouping_columns;
lib/DBIO/Relationship/Base.pm view on Meta::CPAN
}
sub find_or_create_related {
my $self = shift;
my $obj = $self->find_related(@_);
return (defined($obj) ? $obj : $self->create_related(@_));
}
sub update_or_create_related {
#my ($self, $rel, @args) = @_;
shift->related_resultset(shift)->update_or_create(@_);
}
sub set_from_related {
my ($self, $rel, $f_obj) = @_;
$self->set_columns( $self->result_source->_resolve_relationship_condition (
infer_values_based_on => {},
rel_name => $rel,
foreign_values => $f_obj,
foreign_alias => $rel,
self_alias => 'me',
)->{inferred_values} );
return 1;
}
sub update_from_related {
my $self = shift;
$self->set_from_related(@_);
$self->update;
}
sub delete_related {
my $self = shift;
my $obj = $self->search_related(@_)->delete;
delete $self->{related_resultsets}->{$_[0]};
lib/DBIO/Relationship/CascadeActions.pm view on Meta::CPAN
}
$guard->commit;
return $ret;
}
$self->next::method(@rest);
}
sub update {
my ($self, @rest) = @_;
return $self->next::method(@rest) unless ref $self;
# Because update cascades on a class *really* don't make sense!
my $source = $self->result_source;
my %rels = map { $_ => $source->relationship_info($_) } $source->relationships;
my @cascade = grep { $rels{$_}{attrs}{cascade_update} } keys %rels;
if (@cascade) {
my $guard = $source->schema->txn_scope_guard;
lib/DBIO/ResultSet.pm view on Meta::CPAN
$op eq 'update' ? $values : (),
$cond,
) : '0E0';
$guard->commit if $guard;
return $res;
}
sub update {
my ($self, $values) = @_;
$self->throw_exception('Values for update must be a hash')
unless ref $values eq 'HASH';
return $self->_rs_update_delete ('update', $values);
}
sub update_all {
my ($self, $values) = @_;
$self->throw_exception('Values for update_all must be a hash')
unless ref $values eq 'HASH';
my $guard = $self->result_source->schema->txn_scope_guard;
$_->update({%$values}) for $self->all; # shallow copy - update will mangle it
$guard->commit;
return 1;
}
lib/DBIO/ResultSet.pm view on Meta::CPAN
my $self = shift;
my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {});
my $hash = ref $_[0] eq 'HASH' ? shift : {@_};
if (keys %$hash and my $row = $self->find($hash, $attrs) ) {
return $row;
}
return $self->new_result($hash)->insert;
}
sub update_or_create {
my $self = shift;
my $attrs = (@_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {});
my $cond = ref $_[0] eq 'HASH' ? shift : {@_};
my ($main_cond, $related_subconds) = $self->_split_related_update_conds($cond);
# When related sub-structures are peeled off to be applied after the main
# row, wrap the whole operation in a transaction so a partially-built graph
# never survives a failure -- mirroring the multi-create guarantee in
# DBIO::Row::insert. No transaction is opened for the common no-relation case.
lib/DBIO/ResultSet.pm view on Meta::CPAN
next if $concrete_fk;
$related_subconds{$key} = delete $main_cond{$key};
}
return (\%main_cond, \%related_subconds);
}
sub update_or_new {
my $self = shift;
my $attrs = ( @_ > 1 && ref $_[$#_] eq 'HASH' ? pop(@_) : {} );
my $cond = ref $_[0] eq 'HASH' ? shift : {@_};
my $row = $self->find( $cond, $attrs );
if ( defined $row ) {
$row->update($cond);
return $row;
}
lib/DBIO/Row.pm view on Meta::CPAN
$self->_store_inserted_columns(\%current_rowdata, $returned_cols);
$self->store_storage_values if @{$self->storage_value_columns};
return $self;
});
},
sub { $self->insert },
);
}
sub update {
my ($self, $upd) = @_;
# ProxyResultSetMethod (integrated helper): strip proxy slots from the
# dirty-column set so UPDATE statements never include them. "delete
# local" localises the deletion for the scope of this sub, so the
# original dirty flags are restored when update returns.
$self->{_dirty_columns} ||= {};
delete local @{$self->{_dirty_columns}}{@{$self->_proxy_slots||[]}};
# OnColumnChange (integrated helper): short-circuit when nothing is
lib/DBIO/Row.pm view on Meta::CPAN
# StorageValues (integrated helper): snapshot freshly-inflated values.
$new->store_storage_values if @{$new->storage_value_columns};
return $new;
}
sub insert_or_update { shift->update_or_insert(@_) }
sub update_or_insert {
my $self = shift;
return ($self->in_storage ? $self->update : $self->insert);
}
sub is_changed {
return keys %{shift->{_dirty_columns} || {}};
}
lib/DBIO/Storage.pm view on Meta::CPAN
qw/ quote_char name_sep quote_names /;
}
sub select { die "Virtual method!" }
sub insert { die "Virtual method!" }
sub update { die "Virtual method!" }
sub delete { die "Virtual method!" }
sub select_single { die "Virtual method!" }
# Live async backend (a DBIO::Storage::Async) or undef when none configured.
# Overridden in DBIO::Storage::DBI to do real discovery. Base = no backend.
sub _async_storage { undef }
lib/DBIO/Storage.pm view on Meta::CPAN
sub select_async { shift->_run_async('select', @_) }
sub select_single_async { shift->_run_async('select_single', @_) }
sub insert_async { shift->_run_async('insert', @_) }
sub update_async { shift->_run_async('update', @_) }
sub delete_async { shift->_run_async('delete', @_) }
sub txn_do_async { shift->_run_async('txn_do', @_) }
sub future_class {
my $self = shift;
lib/DBIO/Storage/Async.pm view on Meta::CPAN
return $self->_run_crud('select_single', $self->_pool_runner, @_);
}
sub insert_async {
my $self = shift;
return $self->_run_crud('insert', $self->_pool_runner, @_);
}
sub update_async {
my $self = shift;
return $self->_run_crud('update', $self->_pool_runner, @_);
}
sub delete_async {
my $self = shift;
return $self->_run_crud('delete', $self->_pool_runner, @_);
}
lib/DBIO/Storage/Async.pm view on Meta::CPAN
warn "non-transactional DDL on $msg\n";
}
# --- Sync fallbacks ---
# Let sync methods work by blocking on the async result via ->get.
# Useful for scripts/migrations.
sub select { my $self = shift; return $self->select_async(@_)->get }
sub select_single { my $self = shift; return $self->select_single_async(@_)->get }
sub insert { my $self = shift; return $self->insert_async(@_)->get }
sub update { my $self = shift; return $self->update_async(@_)->get }
sub delete { my $self = shift; return $self->delete_async(@_)->get }
sub txn_do { my $self = shift; return $self->txn_do_async(@_)->get }
sub deploy { my $self = shift; return $self->deploy_async(@_)->get }
# --- Schema integration ---
sub schema { $_[0]->{schema} }
sub debug { $_[0]->{debug} }
sub in_txn { 0 }
lib/DBIO/Storage/DBI.pm view on Meta::CPAN
}
catch {
$err = shift unless defined $err;
};
$self->throw_exception($err) if defined $err;
return $count;
}
sub update {
#my ($self, $source, @args) = @_;
shift->_execute('update', @_);
}
sub delete {
#my ($self, $source, @args) = @_;
shift->_execute('delete', @_);
}
lib/DBIO/Timestamp.pm view on Meta::CPAN
my $columns_info = $self->result_source->columns_info;
for my $col (keys %$columns_info) {
next unless $columns_info->{$col}{_timestamp_on_create};
next if defined $self->get_column($col);
$self->store_column($col => $self->get_timestamp);
}
return $self->next::method(@_);
}
sub update {
my $self = shift;
my $upd = shift;
$self->set_inflated_columns($upd) if $upd;
my $columns_info = $self->result_source->columns_info;
for my $col (keys %$columns_info) {
next unless $columns_info->{$col}{_timestamp_on_update};
$self->set_inflated_columns({ $col => $self->get_timestamp });
}