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

public getRowKeyColumns()
inherited from mini\Table\AbstractTable

Get column name(s) that the row key represents

protected getCompareFn()
inherited from mini\Table\AbstractTable

Get the string comparison function for sorting

public limit()
inherited from mini\Table\AbstractTable

Documentation missing

public offset()
inherited from mini\Table\AbstractTable

Documentation missing

public getLimit()
inherited from mini\Table\AbstractTable

Documentation missing

public getOffset()
inherited from mini\Table\AbstractTable

Documentation missing

public withAlias()
inherited from mini\Table\AbstractTable

Documentation missing

public getTableAlias()
inherited from mini\Table\AbstractTable

Get the current table alias (null if not set)

public distinct()
inherited from mini\Table\AbstractTable

Documentation missing

public exists()
inherited from mini\Table\AbstractTable

Documentation missing

public has()
inherited from mini\Table\AbstractTable

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

protected getPrimaryKeyColumn()
inherited from mini\Table\AbstractTable

Get the primary key column definition (cached)

public final getIterator()
inherited from mini\Table\AbstractTable

Iterate over rows with visible columns only

public getColumns()
inherited from mini\Table\AbstractTable

Get columns available for output

public getAllColumns()
inherited from mini\Table\AbstractTable

Get all column definitions regardless of projection

public columns()
inherited from mini\Table\AbstractTable

Narrow to specific columns

public getProperty()
inherited from mini\Table\AbstractTable

Get a property value

public hasProperty()
inherited from mini\Table\AbstractTable

Check if a property exists (including null values)

public withProperty()
inherited from mini\Table\AbstractTable

Return table with property set

Source

src/Table/InMemoryTable.php:43-939