-
Notifications
You must be signed in to change notification settings - Fork 0
Concept Record Anatomy
Turkce Dokumantasyon | English Documentation
Category: Core Concepts & Architecture
Subsystem: Data Model & Serialization (AmberDB::Base)
Entry Type: Architectural Concept
In AmberDB, a database record (document) is physically modeled and manipulated in Perl as a contiguous list of elements (@record). Unlike traditional relational SQL engines that mandate fixed column boundaries, AmberDB records are lightweight, extensible blocks capable of holding primitive scalars, strings, numbers, nested array references (ARRAY-ref), and dictionary mappings (HASH-ref).
The foundational architectural invariant of AmberDB is the 0-Index Primary Key Convention: the very first element ($record[0]) of any record array strictly represents its unique Primary Key ID across all CRUD and indexing pipelines.
Contiguous Record Array (@record)
Index 0 Index 1 Index 2 Index 3 Index 4 ...
Record ID Field / Block 1 Field / Block 2 Field / Block 3 Field / Block 4
(Primary Key) (Scalar/Text) (Relational CSV) (Nested AoA/Ref) (Nested Hash / JSON
-
Auto-Generation: When inserting a new record via
insert_id($table, 0, ...), passing0,undef, or""at index 0 signals the engine to allocate an auto-incrementing 64-bit integer ID. -
Explicit ID: Applications can specify fixed unique IDs (integer or ASCII, depending on
id_type). -
Return Guarantee: All read operations (
read_id,read_all,field_fetch,search_table) guarantee that the returned record list's 0th index is the authoritative record ID.
- Each subsequent position (
$record[1],$record[2],$record[N]) maps to a logical block defined in the table schema (schema/*.table). - Blocks can hold:
- Scalars: Strings, integers, floating-point prices, timestamps.
-
Relational ID Lists: Comma or delimiter-separated strings (e.g.
"5,12,89"). -
Array References (
[... ]): Nested lists, sub-items, variant matrices. -
Hash References (
{ ... }): Arbitrary key-value metadata payloads.
- When stored into the underlying Berkeley DB (
DB_File) master table (.db), AmberDB serializes the array into an optimized internal byte stream. - Internal delimiters separate blocks cleanly, while nested references are serialized using AmberDB's high-speed zero-dependency recursive serializer.
- Unpacking a record from disk deserializes nested references back into native Perl arrayrefs and hashrefs in memory without manual parsing.
use AmberDB;
my $adb = AmberDB->new(path => { dbase_dir => "./dbstore" });
# 1. Define record array with 0 at index 0 for auto-increment ID
my @record = (
0, # [0] Auto-increment ID
"Wireless Noise-Canceling Headphones", # [1] Title (Scalar)
"Electronics,Audio", # [2] Category Tags (CSV)
249.99, # [3] Price (Numeric)
["Black", "Silver", "Midnight Blue" ], # [4] Variants (ARRAY reference)
{ bluetooth => "5.3", anc => 1 }, # [5] Specifications (HASH reference)
);
# 2. Insert record - returns allocated ID and assigns to $record[0]
my $id = $record[0] = $adb->insert_id("catalog_product", @record);
print "Created Product with ID: $id\n";
# 3. Read back from database
my @fetched = $adb->read_id("catalog_product", $id);
my $product_id = $fetched[0]; # 1001
my $title = $fetched[1]; # "Wireless Noise-Canceling Headphones"
my $variants = $fetched[4]; # ["Black", "Silver", "Midnight Blue" ]
my $specs = $fetched[5]; # { bluetooth => "5.3", anc => 1 }
# 4. Modify price and save back
$fetched[3] = 199.99;
$adb->modify_id("catalog_product", @fetched);Important
Array Offset Alignment:
Schema block configurations (such as match_block => [1, 2 ], search_block => [1 ], sort_block => [ 3 ], slug_block => [ 1, 2 ]) directly refer to the 1-based data block positions in @record. Block 1 is $record[1], Block 2 is $record[2], etc. Never configure block 0 for search or facet indexing, as block 0 is reserved exclusively for the primary key.
Warning
Modifying Records In-Place:
When updating a record with modify_id("table", @record), ensure $record[0] contains the valid existing record ID. Overwriting $record[0] with 0 or another ID during modification will result in record corruption or key mismatch errors.
AmberDB — High-Performance Schema-Driven NoSQL Database Engine for Perl.
Copyright 2005-2026 Maruf Cetin. Released under the Artistic License 2.0.
CPAN · GitHub Repository · Issue Tracker
- Berkeley DB (DB_File) Engine
- AmberDB Table Schema
- Global Flags
- Table Schema Flags
- Directory Structure
- File Structure (Extensions)
- Repeat Blocks
- Auto-Increment ID
- ASCII ID
- Relational Records
- Record Anatomy
- JOIN-Free Architecture
- Packed Binary Index
- Strict 2PL Locking
- Undo Journal & Rollback
- Tiered Junk Indexing
- Disjunctive Faceting
- Phonetic Accent Search
- 2-Pillar Disaster Recovery
- RAM-Disk Acceleration
- In-Memory Schema Mutation
- Simple Mode
- new
- config
- set_datadir
- insert_id
- insert_list
- modify_id
- modify_list
- delete_id
- delete_list
- read_id
- read_all
- read_list
- exist_id
- exist_list
- exist_table
- table_count
- table_keys
- table_lastid
- table_attr
- table_create
- field_fetch
- field_filter
- search_table
- facet_menu
- field_fltkeys
- field_allfltkeys
- facet_rules
- slug_read
- slug_fetch
- transact_start
- transact_end
- transact_commit
- transact_rollback
- transact_recover
- flock_open
- flock_close
- cache_setup
- cache_read
- cache_write
- cache_delete
- cache_preload
- cache_ensure
- buffer_write
- buffer_read
- buffer_delete
- recs_scan
- recs_get
- recs_put
- recs_del
- locale_uc
- locale_lc
- locale_sort
- locale_to_ascii
- locale_num2text
- locale_format_currency
- locale_format_date
- array_sort
- array_punch
- array_filter
- array_sublist
- deep_copy
- log_owner
- use_counter
- use_junk
- keep_deleted
- auto_id
- buffer_write
- simple
- no_write
- no_backup
- jnktype
- keys_only
- id_type
- language
- .db · .table · .dbase
- .inx · .fld · .src
- .fac · .srt · .slg
- .unq · .del · .aut
- .cnt · .txn · .amberdb
- .csv · .cache · .tmp