AmberDB

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN


        - [CLI ENGINE VERSION INTROSPECTION]
          * Added '--version', '-v', and 'version' commands to bin/amberdb_cli.pl.
          * Emits standard release banner 'AmberDB v<VERSION> (CLI)' or structured JSON schema when combined with 'format=json'.

        - [DOCUMENT-STORE SINGLE HASH / REFERENCE ENCODING FIX]
          * Fixed AmberDB::recs_put to ensure single reference record payloads (HASH/ARRAY, e.g. 'data={...}') are passed through db_encode rather than stringified to 'HASH(0x...)'.
          * Verified complete recursive serialization and round-trip fidelity for deeply nested hashes and arrays inside array records (tested in t/amberdb_escape_encode.t).

        - [CLI DEFAULT TABLE OUTPUT RENDERING & POSITIONAL ARGUMENTS]
          * Configured clean, formatted ASCII box tables ('+----+----+') as default CLI output for single records ('read <table_name> <id>') and multi-record lists ('read all', 'search', 'fetch'), replacing legacy Data::Dumper fallback.
          * Enhanced CLI positional argument parsing for multi-block records, enabling seamless scalar, JSON array, and JSON hash parameters directly via command line (e.g. 'amberdb insert items 0 "Mouse" \'["wireless","bt"]\' \'{"brand":"Razer"}\'')...
          * Fixed TSV output formatting ('format=tsv' / 'tsv') to join record fields strictly with tabs on a single line ('<id>\t<field_1>\t<field_2>...') instead of splitting fields across separate newlines.
          * Preserved full backwards compatibility with explicit format switches: 'format=dumper' / 'dumper', 'format=json' / 'json', 'format=pretty' / 'pretty', and 'format=tsv' / 'tsv'.
          * Added bilingual command-line usage screen support: 'amberdb usage' / 'amberdb help' renders in English, while 'amberdb usage.tr' / 'amberdb help.tr' (or 'usage tr') renders in Turkish.
          * Added subtest 13 in t/amberdb_cli.t to verify default table output, TSV tab separation, column headers, and explicit dumper formatting.

5.26.1  2026-09-28
        - [32-BIT PERL / CPAN TESTERS QUAD PACKING COMPATIBILITY]
          * Implemented transparent cross-platform 64-bit integer packing in AmberDB::Base::Encoder (_pack_ids, _unpack_ids, _pack_single_id).
          * Utilizes native 64-bit pack("(Q>)*") / unpack("(Q>)*") on 64-bit Perls with zero performance overhead.

bin/amberdb_cli.pl  view on Meta::CPAN

# Direct file-based embedded execution, token-based session lifecycle, dynamic method reflection, and dash-tolerant argument parser.

use 5.016;
use strict;
use warnings;
use File::Basename qw(dirname basename);
use Cwd qw(abs_path getcwd);
use File::Spec;
use File::Path qw(make_path remove_tree);
use JSON::PP qw(encode_json decode_json);
use Data::Dumper;
use Time::HiRes qw(gettimeofday tv_interval);

our $t0 = [gettimeofday];

BEGIN {
    my $script_path = __FILE__;
    $script_path =~ s{[\\/]+}{/}g;
    my $bin_dir = $script_path =~ m{^(.*)/[^/]+$} ? $1 : '.';
    my $lib_dir = "$bin_dir/../lib";
    my $abs_lib = eval { abs_path($lib_dir) } // $lib_dir;

bin/amberdb_cli.pl  view on Meta::CPAN

=head1 OUTPUT FORMATS

The output format can be controlled using C<format=E<lt>typeE<gt>>:

=over 4

=item * C<table:> (Default) Human-readable ASCII terminal table.

=item * C<json:> Machine-readable JSON output, ideal for shell pipelines, Web UIs, and external scripts.

=item * C<raw:> Direct Perl Data::Dumper serialization.

=back

=head1 SEE ALSO

L<AmberDB>, L<AmberDB::Tools>, L<amberdb_setup.pl>

Official Wiki: L<https://github.com/marufcetin/amberdb/wiki/Guide-CLI>

=head1 AUTHOR

lib/AmberDB/Base.pm  view on Meta::CPAN

}

sub _save_connect_config {
    my ( $self, $data ) = @_;
    my $file = $self->_connect_file();
    return unless defined $file && ref($data) eq 'HASH';

    my ($dir) = $file =~ m{^(.+)[/\\][^/\\]+$};
    $self->make_path($dir) if $dir && !$self->dir_exist($dir);

    require Data::Dumper;
    local $Data::Dumper::Terse    = 1;
    local $Data::Dumper::Indent   = 1;
    local $Data::Dumper::Sortkeys = 1;
    my $dump = Data::Dumper::Dumper($data);
    $dump =~ s/^\s+|\s+$//g;

    if ( open my $fh, '>', $file ) {
        print $fh "# AmberDB Database Connection & Client Auth Profile\n";
        print $fh "return " . $dump . ";\n";
        close $fh;
        return 1;
    }
    return 0;
}

lib/AmberDB/Base.pm  view on Meta::CPAN


sub _save_session {
    my ( $self, $token, $data ) = @_;
    return unless defined $token && length $token;
    my $sf = $self->session_file($token);
    return unless $sf;

    my ($dir) = $sf =~ m{^(.+)[/\\][^/\\]+$};
    $self->make_path($dir) if $dir && !$self->dir_exist($dir);

    require Data::Dumper;
    local $Data::Dumper::Terse    = 1;
    local $Data::Dumper::Indent   = 1;
    local $Data::Dumper::Sortkeys = 1;
    my $dump = Data::Dumper::Dumper($data);
    $dump =~ s/^\s+|\s+$//g;

    if ( open my $fh, '>', $sf ) {
        print $fh "# AmberDB Active CLI Session Token: $token\n";
        print $fh "return " . $dump . ";\n";
        close $fh;
    }

    # Also sync local .amberdb/session/sess_$token
    my $local_dir = ".amberdb/session";

t/amberdb_cli.t  view on Meta::CPAN


    # Insert a document-store record
    `"$perl_bin" -Ilib "$cli_path" $token insert tbl_table_view 1 data='{"name":"Ahmet","role":"admin"}'`;

    # Read without format: should render box table with 0, 1 index headers by default
    my $out_tbl = `"$perl_bin" -Ilib "$cli_path" $token read tbl_table_view 1`;
    like( $out_tbl, qr/\+----+/, "Default output has box table border" );
    like( $out_tbl, qr/\|\s*0\s*\|\s*1\s*\|/, "Default output contains index headers 0 and 1" );
    like( $out_tbl, qr/Ahmet/, "Default output contains data payload" );

    # Read with explicit dumper format: should render Data::Dumper
    my $out_dump = `"$perl_bin" -Ilib "$cli_path" $token read tbl_table_view 1 dumper`;
    like( $out_dump, qr/\$VAR1\s*=/, "Explicit dumper format produces Data::Dumper output" );

    # Read with explicit tsv format: should render tab-separated fields on a single line
    my $out_tsv = `"$perl_bin" -Ilib "$cli_path" $token read tbl_table_view 1 tsv`;
    chomp $out_tsv;
    like( $out_tsv, qr/^1\t\{.*"?name"?\s*:\s*"?Ahmet"?.*\}$/, "Explicit tsv format produces tab-separated line without newline splitting" );

    # Insert second record with nested data hash and auto-id 0: data='{"data":{"name":"Maruf","age":"50"}}'
    `"$perl_bin" -Ilib "$cli_path" $token insert tbl_table_view 0 data='{"data":{"name":"Maruf","age":"50"}}'`;

    # Read all with default table view



( run in 1.376 second using v1.01-cache-2.11-cpan-c32d3c3b8f1 )