AmberDB
view release on metacpan or search on metacpan
lib/AmberDB.pm view on Meta::CPAN
unless ( $self->config('no_backup') || $table_info->{no_backup} ) {
$self->recs_back( "add", $tableid, @batch );
}
}
return \%statu;
}
# Replace the DB record with new data.
# ------------------------------------------------
sub update_id {
my ( $self, $tableid, $rid, @record ) = @_;
# Perform the checks.
$tableid or return;
if ( ref($rid) eq 'HASH' && !@record ) {
my $h = { %$rid };
$rid = $h->{id} // $h->{ID};
@record = ($h);
lib/AmberDB.pm view on Meta::CPAN
# Authorization
$self->auth_write( $tableid, $table_path, "edit", $rid ) unless $is_async_write;
return 1;
}
# List record modify.
# Note: Bulk operations (insert_list, modify_list, delete_list) do NOT use transactions (_txn_log).
# ------------------------------------------------
sub update_list {
my ( $self, $tableid, @records ) = @_;
local $self->{_no_txn} = 1;
$tableid or return {};
scalar @records or return {};
# Deflate if records contain hashrefs or if single arrayref of hashes or HoH
if ( @records == 1 && ref($records[0]) eq 'ARRAY' && @{$records[0]} && ref($records[0]->[0]) eq 'HASH' ) {
lib/AmberDB.pm view on Meta::CPAN
sub modify_list { shift->update_list(@_) }
# Updates a field value in an existing record.
# Supports updating fixed schema blocks:
# $adb->update_field($table, $rid, "price", 1750)
# $adb->update_field($table, $rid, block => "price", 1750)
# Supports updating repeating child items by 'id' or 'pos':
# $adb->update_field($table, $rid, id => 202, $new_item)
# $adb->update_field($table, $rid, pos => 0, $new_item)
# ------------------------------------------------
sub update_field {
my $self = shift;
my $tableid = shift;
my $rid = shift;
$tableid or return;
$rid = $self->id_check( $tableid, $rid );
$rid or return;
my ( $target_spec, $new_val );
if ( @_ == 3 && !ref($_[0]) ) {
lib/AmberDB/Tools.pm view on Meta::CPAN
}
# ---------------------------------------------------------------------
# update_table($tableid, %options)
# Scans an entire table record-by-record, detects any legacy formats (2003-2026),
# creates a timestamped backup with detected dominant version, and rewrites the table
# directly in ABR v1 format preserving original IDs.
# Rebuilds indexes using $self->set_index($tableid).
# Preserves companion data files ('del', 'aut').
# ---------------------------------------------------------------------
sub update_table {
my ( $self, $tableid, %opts ) = @_;
my $adb = $self->{_adb} or return;
$tableid or return;
my $table_path = $adb->table_path($tableid);
my $ext = $adb->{db_ext} || "db";
my $file_path = "$table_path.$ext";
# Use exist_table to verify primary table existence
return { status => 'not_found', table => $tableid }
lib/AmberDB/Tools.pm view on Meta::CPAN
unq_backup => $unq_backup,
has_cnt => $has_cnt ? 1 : undef,
cnt_backup => $cnt_backup,
};
}
# ---------------------------------------------------------------------
# update_all(%options)
# Iterates through all discovered tables and runs update_table on each.
# ---------------------------------------------------------------------
sub update_all {
my ( $self, %opts ) = @_;
my $adb = $self->{_adb} or return;
my @tables = $self->all_tables();
my @results;
foreach my $table (@tables) {
my $res = $self->update_table( $table, %opts );
push @results, $res if $res;
}
( run in 2.789 seconds using v1.01-cache-2.11-cpan-364913b4093 )