mini\Database\VirtualDatabase
class
Documentation
Virtual database that executes SQL against registered TableInterface instances
Implements DatabaseInterface to provide a drop-in replacement for PDODatabase when working with in-memory table data structures.
Phase 1: Single-table operations
- SELECT with WHERE, ORDER BY, LIMIT, column projection
- INSERT, UPDATE, DELETE on MutableTableInterface
- Subqueries in IN clauses: WHERE col IN (SELECT ...)
Future phases will add JOINs, aggregates, DISTINCT, correlated subqueries.
Usage:
$vdb = new VirtualDatabase();
$vdb->registerTable('users', $usersTable);
$vdb->registerTable('orders', $ordersTable);
// SELECT queries return ResultSetInterface
foreach ($vdb->query('SELECT name, email FROM users WHERE status = ?', ['active']) as $row) {
echo $row->name;
}
// INSERT/UPDATE/DELETE return affected row count
$affected = $vdb->exec('DELETE FROM users WHERE id = ?', [123]);
Inheritance
Implements:
mini\Database\DatabaseInterface
Properties (12)
array $tables
array $aggregates
ReflectionProperty $astProperty
Reflection accessors for PartialQuery to avoid cloning overhead
ReflectionMethod $ensureAstMethod
string $lastInsertId
Last insert ID from most recent INSERT
WeakMap $queryMap
float $queryTimeout
Maximum query execution time in seconds (null = no limit)
float $queryStartTime
Query start time for timeout tracking
string $tableClass
Table class to use for CREATE TABLE (InMemoryTable or ArrayTable)
Current session for temp table resolution (set during query execution)
Methods (149)
Documentation missing
Register a custom aggregate function
Check if a function name is a registered aggregate
Set maximum query execution time in seconds
Use ArrayTable instead of InMemoryTable for CREATE TABLE
Create a new session for this database
Execute a SELECT query with session context
Execute an INSERT/UPDATE/DELETE/DDL with session context
Check if current query has exceeded timeout
Check if SELECT columns contain any aggregate function calls
Recursively check if an expression contains an aggregate function
Check if any column contains a window function
Recursively check if an expression contains a window function
Register built-in SQL aggregate functions
Register a table with a name
Get a registered table by name
Get all registered table names
Create a new VirtualDatabase with shadowed tables
Execute a SELECT query
Wrap a PartialQuery in a Query and register the mapping
Get the underlying PartialQuery for a Query instance
Get AST from PartialQuery without cloning using reflection
Get a raw query executor closure for PartialQuery
Wrap an iterable with timeout checking
Generator that checks for timeout every 100 rows
Create raw executor closure with session context
Execute INSERT with session context
Execute UPDATE with session context
Execute DELETE with session context
Execute CREATE TABLE with session context
Execute DROP TABLE with session context
Execute an INSERT, UPDATE, DELETE, or DDL statement
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
{@inheritdoc}
Execute a UNION query as TableInterface
INTERSECT: rows that exist in both tables
EXCEPT: rows from left that don't exist in right
Execute a branch of a UNION as TableInterface
Execute a WITH statement (CTE)
Check if a CTE references itself (is recursive)
Check if an AST node references a specific table name
Execute a recursive CTE
Rename row columns to match expected column names
Execute a CTE query and return as TableInterface
Convert stdClass rows to InMemoryTable
Rename CTE table columns according to specified column list
Documentation missing
Execute a SELECT with window functions
Collect window functions from SELECT columns
Extract all WindowFunctionNode instances from an expression
Generate a unique alias for a window function
Compute window function values for all rows
Compute partition key from PARTITION BY expressions
Compare two rows for window ORDER BY
Evaluate window function for a sorted partition
Project a row with window function values
Evaluate expression, substituting window function results
Compare two rows for ORDER BY (for result sorting)
Execute an aggregate SELECT (e.g., SELECT COUNT(*), SUM(price) FROM orders)
Execute aggregate without GROUP BY (single group containing all rows)
Execute aggregate with GROUP BY
Clone aggregate infos with fresh contexts for a new group
Step all aggregates with values from a row
Build result row from finalized aggregates and non-aggregate columns
Collect non-aggregate columns from SELECT
Sort result rows by ORDER BY specification
Sort results that include both projected and original row data
Collect aggregate function info from SELECT columns
Execute a SELECT and return as TableInterface (for subqueries)
Execute SELECT with CROSS JOINs using predicate pushdown optimization
Flatten an AND-connected expression into a list of predicates
Find which tables are referenced in a predicate
Try to extract equi-join columns from a predicate
Resolve a column identifier to its fully qualified name (table.column)
Recursively collect table references from an expression
Rebuild an AND expression from a list of predicates
Execute a subquery and return as SetInterface for IN clause
Execute a derived table (subquery in FROM position)
Infer column definitions from a SELECT statement (for empty derived tables)
Execute a subquery with outer row context for correlated subqueries
Execute aggregate query on pre-filtered rows
Extract simple column names from SELECT columns
Apply EXISTS operation to table
Find outer references in a subquery WHERE clause
Recursively collect outer references from AST node
Check if WHERE clause contains OR with outer references
Check if AST node references a specific table
Try to apply correlated EXISTS using ExistsTable (hash-based, much faster)
Find a column in the table's columns, handling qualified/unqualified names
Parse a column reference to determine if it's inner or outer table
Check if a predicate references a specific column
Apply correlated EXISTS using row-by-row evaluation
Evaluate correlated EXISTS by iterating subquery table and testing WHERE
Evaluate WHERE expression with row data and outer context
Evaluate expression value with row data and outer context
Build a Table template with binds for outer references
Apply WHERE clause, converting outer references to binds
Project a row to only the requested columns
Documentation missing
Execute INSERT INTO ... SELECT ... statement
Find the primary key column name for a table
Delete a row by primary key value (for REPLACE)
Documentation missing
Check if an expression contains column references (needs row context to evaluate)
Execute UPDATE with row-by-row evaluation for self-referencing expressions
Documentation missing
Execute CREATE TABLE - creates a table with the given schema
Execute DROP TABLE - removes a registered table
Convert AST ColumnDefinition to ColumnDef
Map SQL data type string to ColumnType enum
Apply a WHERE clause AST to a TableInterface using table methods
Check if a predicate can be pushed to the table interface
Apply a single pushable predicate to the table
Filter table rows by evaluating an expression against each row
Apply IN filter with index-aware optimization
Apply ALL/ANY quantified comparison
Check if comparison is true for ALL values (ALL quantifier)
Check if comparison is true for at least one value (ANY quantifier)
Perform a single comparison
Try to simplify arithmetic comparison to pushable form
Solve for column in arithmetic comparison
Flip comparison operator (for negative multiplier or subtraction from constant)
Check if an arithmetic expression contains NULL literal
Build a Predicate from an AST node (for OR clauses)
Append conditions from AST node to existing Predicate
Apply ORDER BY clause using table's order() method
Check if ORDER BY contains expressions or aliases that need evaluation
Execute SELECT with expression-based ORDER BY
Apply a WHERE clause AST to build a query for mutations
Execute SELECT without FROM (scalar expressions)
Build SingleRowTable from SELECT without FROM
Convert expression AST to column name string
Apply a JOIN clause to a table
Build a Predicate with bind parameters from a JOIN ON condition
Append join conditions to a predicate
Build qualified column name from identifier node
Resolve a column name against a table's actual columns