Home  •  About  •  Quick Start  •  Tutorial  •  Benchmark  •  Locale  •  SQL Guide  •  Changes  •  Wiki  •  Türkçe

AmberDB for SQL Developers: A Comparative Practical Guide

This guide is designed for software engineers coming from traditional relational database management systems (RDBMS / SQL) who want to quickly build applications with AmberDB. Rather than focusing on abstract theory or database philosophy, it adopts a direct "In SQL it is done like X, in AmberDB it is done like Y" approach with production-ready Perl code examples.

Table of Contents

  1. Essential Practical Notes for Developers (Quick Intro)
  2. Basic CRUD Operations (DML)
  3. Querying, Filtering, and Search (SELECT, WHERE, LIKE)
  4. Sorting (ORDER BY) and Multilingual Collation
  5. Relationships and JOINs: The Core Architectural Difference
  6. Grouping and Filter Facet Counters (GROUP BY vs. Facet)
  7. Transaction Safety and ACID (COMMIT & ROLLBACK)
  8. Data Definition (DDL: CREATE TABLE vs. AmberDB Schema)
  9. Built-in AmberDB Capabilities Beyond Standard SQL
  10. Quick Reference Cheat Sheet
  11. Terminology Glossary

1. Essential Practical Notes for Developers (Quick Intro)

Before writing queries, keep these 4 operational rules in mind:

  1. No External Database Server or Daemon: There is no mysqld or postgres background daemon to start, configure, or connect to over TCP. AmberDB is an embedded Perl object running directly inside your application process:
    use AmberDB;
    my $adb = AmberDB->new(
        cfg  => { user => 'admin', language => 'en' },
        path => { dbase_dir => './dbstore' }
    );
    
  2. Records Are Native Perl Arrays (@record): An SQL table row corresponds to a native Perl array ($id, $field1, $field2, ...).
  3. Index 0 is ALWAYS the Primary Key ID: The first element ($record[0]) is the unique identifier. Pass 0 or undef when inserting; insert_id assigns and returns the auto-incremented ID.
  4. Positional Block Indices Instead of Column Names: Instead of named columns (name, price), AmberDB uses positional block indices (1, 2, 3...). Each block can hold scalars, nested ARRAY references, or HASH references directly.

[!NOTE] For deep architectural mechanics, disk file specs, and benchmarks, refer to About AmberDB, Comprehensive Developer Guide, and Large-Scale Benchmark.

2. Basic CRUD Operations (DML)

2.1 INSERT (Single Record)

2.2 BULK INSERT (Batch Ingestion)

2.3 SELECT by ID (Primary Key Point Read)

2.4 UPDATE by ID (Single Record Mutation)

2.5 BULK UPDATE (Batch Mutation)

2.6 DELETE (Single Record Deletion & Soft-Delete)

2.7 BULK DELETE (Batch Deletion)

2.8 COUNT(*) (Table Record Count)

3. Querying, Filtering, and Search (SELECT, WHERE, LIKE)

3.1 Exact Match (WHERE field = value)

3.2 Multi-Value IN Lookup (WHERE id IN (...))

3.3 Text Search (WHERE col LIKE '%...%' / FTS)

3.4 Compound Multi-Field Filtering (WHERE A = x AND B = y)

3.5 Pagination (LIMIT & OFFSET)

4. Sorting (ORDER BY) and Multilingual Collation

4.1 Numeric and Text Sorting

4.2 Multilingual and Turkish Character Collation

5. Relationships and JOINs: The Core Architectural Difference

5.1 SQL Normalized Multi-Table + JOIN Model

SQL requires normalizing orders, line items, and products across separate tables joined via foreign keys:

SELECT o.id AS order_id, o.customer_name, oi.product_id, oi.quantity, p.name AS product_name
FROM orders o
JOIN order_items oi ON o.id = oi.order_id
JOIN products p ON oi.product_id = p.id
WHERE oi.product_id = 101;

Cost: Multiple B-Tree traversals, cross-table random disk seeks, temporary sorting buffers, and query-planner CPU overhead.

5.2 AmberDB Embedded Document + match_block Inverted Index Model

AmberDB embeds line items directly into the order record as a native Perl array reference (ARRAY ref):

my @order = (
    0,                             # [0] Order ID (auto-generated)
    "Ahmet Yılmaz",                # [1] Customer Name
    "2026-09-06",                  # [2] Date
    [                              # [3] Line Items (Nested ARRAY): [ [ ProductID, Qty, Price ], ... ]
        [ 101, 2, 149.99 ],
        [ 105, 1,  49.90 ],
    ],
    { status => "shipped" }        # [4] Metadata (HASH ref)
);

my $order_id = $adb->insert_id("orders", @order);

Schema declaration (orders.table):

{
    match_block => [ 3 ], # Index all nested item IDs automatically
}

Query: "Find all orders containing Product 101":

6. Grouping and Filter Facet Counters (GROUP BY vs. Facet)

In e-commerce, sidebar facet counters such as "Sony (12), Apple (8), Samsung (5)" require SQL GROUP BY aggregates.

7. Transaction Safety and ACID (COMMIT & ROLLBACK)

AmberDB provides crash-safe undo-log transaction management and Strict 2PL (Two-Phase Locking).

8. Data Definition (DDL: CREATE TABLE vs. AmberDB Schema)

9. Built-in AmberDB Capabilities Beyond Standard SQL

Common tasks that require external libraries, database triggers, or external cache daemons in SQL stacks are natively built into AmberDB:

| Feature | Standard Solution in SQL | Built-in AmberDB Solution | |---|---|---| | Automatic SEO URL Slugs | Custom slugify code, database uniqueness check queries. | slug_block => [1] automatically creates collision-free slugs like /product/sony-wh-1000xm5 upon insert/update (get_slug). | | User Audit Trail (Audit Log) | Separate audit tables, database triggers, or ORM event hooks. | log_owner => 1 logs every modification into .aut. Call $adb->auth_view("table", $id) for an instant HTML timeline. | | High-Speed In-Memory Caching & Ephemeral Data (RAM-Disk) | Installing and managing external caching servers (Redis or Memcached) to bypass disk I/O bottlenecks, managing TCP network overhead and cache-sync logic. | Zero external servers or daemons required: in-process L1 object caching (set_cache, get_cache) plus OS-level physical RAM-Disk acceleration (use_ramdisk, ramdisk_*) running directly on Berkeley DB files. Zero network hops, zero service dependencies. | | Safe Soft-Delete | Adding is_deleted column and remembering WHERE is_deleted = 0 on every query. | keep_deleted => 1 moves deleted records to a .del archive. Prevents data leaks with zero query filtering overhead. |

10. Quick Reference Cheat Sheet

A side-by-side mapping for common database operations:

| SQL Statement | AmberDB Method | AmberDB Usage Example | |---|---|---| | INSERT INTO t VALUES (...) | insert_id | $id = $adb->insert_id("t", 0, @fields); | | INSERT INTO t VALUES (...), (...) | insert_list | $adb->insert_list("t", @records); | | SELECT * FROM t WHERE id = ? | read_id | my @rec = $adb->read_id("t", $id); | | SELECT * FROM t WHERE id IN (...) | read_list | my @recs = $adb->read_list("t", $res->{ids}); | | SELECT * FROM t LIMIT 20 OFFSET 0 | read_all | my ($tot, @recs) = $adb->read_all("t", { offset => 0, limit => 20 }); | | UPDATE t SET ... WHERE id = ? | update_id | $adb->update_id("t", @updated_rec); | | DELETE FROM t WHERE id = ? | delete_id | $adb->delete_id("t", $id); | | DELETE FROM t WHERE id IN (...) | delete_list | $adb->delete_list("t", @id_list); | | SELECT COUNT(*) FROM t | table_count | my $count = $adb->table_count("t"); | | SELECT * FROM t WHERE col = val | field_fetch | my @recs = $adb->field_fetch("t", $blk, $val); | | SELECT * FROM t WHERE col LIKE '%s%' | search_table | my @recs = $adb->search_table("t", "term"); | | SELECT * FROM t WHERE a=? AND b=? | field_filter | $adb->field_filter("t", { filter => { 1 => $a, 2 => $b } }); | | SELECT col, COUNT(*) GROUP BY col | field_fltkeys| $adb->field_fltkeys("t", { target_block => $blk, filter => { $fld => $val } }); | | START TRANSACTION / COMMIT | transact_* | $adb->transact_start(); ... $adb->transact_end(); | | CREATE TABLE / CREATE INDEX | table_attr | $adb->table_attr("t", { match_block => [ 1, 2 ] }); |

11. Terminology Glossary

Mapping SQL and relational concepts to AmberDB architecture:

| SQL / Relational Concept | AmberDB Equivalent | Technical Meaning | |---|---|---| | Database Server / Instance | AmberDB Object ($adb) | No background daemon or TCP port; lives embedded inside the application process. | | Table | Table (.db) | Key-value store backed by Berkeley DB (DB_File Hash). | | Row / Record | Array Record (@record) | Flexible Perl list rather than fixed-width C struct. Holds scalars, ARRAY refs, or HASH refs. | | Column / Field | Block Index ($record[$i]) | Positional block index (1, 2, 3...) instead of column names. | | Primary Key (AUTO_INCREMENT) | Index 0 ($record[0]) | The first element of the array. Auto-assigned monotonic numeric ID. | | Foreign Key & JOINs | Nested Arrays & match_block | Denormalized documents with embedded lists; inverted index (.fld) provides $O(1)$ relationship lookups with zero JOINs. | | Index (CREATE INDEX) | Schema Index Blocks | Inverted secondary indexes: Match (.fld), Full-text (.src), Facet (.fac), Sort (.inx). | | Query Optimizer / Planner | Direct Key Seeks | Zero SQL parsing and cost compilation; binary RID blocks are read directly from disk. | | Collation / Charset | AmberDB::Locale | Embedded multi-language and Turkish alphabet folding without external libc collation dependencies. | | Audit Table & Triggers | log_owner & .aut | Built-in modification tracking recording user and timestamp. | | Soft-Delete (is_deleted) | keep_deleted & .del | Deleted records are isolated in an archive file, preventing accidental data leaks. | | External Cache / Session Server (Redis / Memcached Alternative) | set_cache / get_cache & RAM-Disk (use_ramdisk) | Without managing a separate daemon/server: in-process L1 object caching and OS-level shared memory RAM-Disk acceleration for critical and ephemeral tables with TTL support. |