API Documentation

Complete reference for all database functions

create_db()

CREATE

Creates a new database with index and record files.

create_db(string $dbname): void

// Example
create_db('my_database');
// Creates: my_database/db.ivr and my_database/db.idx

add_record()

WRITE

Adds a new record to the database.

add_record(string $dbname, array $data): string

// Example
$id = add_record('users', [
    'name' => 'John Doe',
    'email' => 'john@example.com',
    'age' => 30
]);
// Returns: record ID (hash)

read_row()

READ

Reads a specific record by ID with version history.

read_row(string $dbname, string $record_id): ?RecordHistory

// Example
$row = read_row('users', $id);
$latest = $row->latest();           // Get latest version
$all = $row->all_versions();        // Get all versions
$count = $row->num_versions();      // Version count
$specific = $row->version(2);       // Get version 2

read_all()

READ

Reads all records from database.

read_all(string $dbname, bool $include_deleted = false): array

// Example
$records = read_all('users');              // Active only
$all = read_all('users', true);           // Include deleted

foreach ($records as $id => $record) {
    echo $record->data->name;
    echo $record->timestamp;
}

update_record()

UPDATE

Updates an existing record (creates new version).

update_record(string $dbname, string $record_id, array $new_data): bool

// Example
$success = update_record('users', $id, [
    'name' => 'Jane Doe',
    'email' => 'jane@example.com',
    'age' => 31
]);
// Returns: true on success
// Previous version preserved in history

delete_record()

DELETE

Soft-deletes a record (can be restored).

delete_record(string $dbname, string $record_id, bool $hard_delete = false): bool

// Example
delete_record('users', $id);              // Soft delete
delete_record('users', $id, true);        // Hard delete (permanent)

filter_records()

FILTER

Filters records using custom callback function.

filter_records(string $dbname, callable $filter_fn): array

// Example 1: Simple filter
$adults = filter_records('users', function($record) {
    return $record->data->age >= 18;
});

// Example 2: Complex filter
$results = filter_records('users', function($record) {
    return str_contains($record->data->email, '@gmail.com') 
        && $record->data->age > 25;
});

// Example 3: Field exists check
$with_phone = filter_records('users', function($record) {
    return isset($record->data->phone);
});

Filter Operators

Contains

stripos($value, $search) !== false

Case-insensitive substring match

Equals

$value === $search

Exact match

Starts With

strpos($value, $search) === 0

Begins with search term

Ends With

substr($value, -strlen($search)) === $search

Ends with search term