mini\Table\InMemoryTable class

Documentation

SQLite-backed in-memory table implementation

Intended as a ground-truth oracle for testing - all operations are translated to SQL and executed by SQLite, which provides well-defined semantics for filtering, sorting, and set operations.

$table = new InMemoryTable(
    new ColumnDef('id', ColumnType::Int, IndexType::Primary),
    new ColumnDef('name', ColumnType::Text, IndexType::Index),
    new ColumnDef('age', ColumnType::Int),
);

$table->insert(['id' => 1, 'name' => 'Alice', 'age' => 30]);
$table->insert(['id' => 2, 'name' => 'Bob', 'age' => 25]);

foreach ($table->gt('age', 20)->order('name ASC') as $id => $row) {
    echo "$row->name is $row->age\n";
}

Inheritance

Extends: mini\Table\AbstractTable

Implements: mini\Table\Contracts\TableInterface Traversable Countable IteratorAggregate mini\Table\Contracts\SetInterface mini\Table\Contracts\MutableTableInterface

Properties (9)

private SQLite3 $db
private string $tableName
private array $where
private array $orGroups

OR groups - when non-empty, WHERE becomes: (group1) OR (group2) OR ...

private array $orderBy
private int $paramCounter
protected ?Closure $compareFn
protected ?int $limit
protected int $offset

Methods (53)

Create a new in-memory table with the given schema

Share database connection on clone (filters are query-level state)

Quote a SQLite identifier (column/table name).

Create the SQLite table with proper schema

Documentation missing

Coerce a value based on column type

Coerce a filter value based on column type

Documentation missing

Documentation missing

Validate that a query is derived from this table

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Create SQL UNION of two InMemoryTable queries on same DB

Renumber parameter names in condition groups to avoid collision

Create SQL EXCEPT (NOT IN) of two InMemoryTable queries on same DB

Extract filter conditions from a Predicate

Build IN condition from SetInterface

Build WHERE clause and parameter bindings

Build a group of AND conditions

Build ORDER BY clause

Build LIMIT/OFFSET clause

Documentation missing

Format Decimal column values from scaled integer to decimal string

Documentation missing

Documentation missing

Get column name(s) that the row key represents

Get the string comparison function for sorting

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Get the current table alias (null if not set)

Documentation missing

Documentation missing

Check if value(s) exist in the table's projected columns

Get the primary key column definition (cached)

Iterate over rows with visible columns only

Get columns available for output

Get all column definitions regardless of projection

Narrow to specific columns

Get a property value

Check if a property exists (including null values)

Return table with property set

Source

src/Table/InMemoryTable.php:43-939