Skip to content

Internals Database

Stefan Crkvenjakov edited this page Oct 7, 2026 · 1 revision

Database internals

Framework Internals · Developer guide

DatabaseManager composes IProvider, QueryBuilder and ICache. QueryBuilder validates identifiers for tables/filter keys/order/update/insert columns, generates placeholders and returns QueryPayload(sql, bindings, table, conditions). select column lists and legacy join ON strings remain trusted SQL. where/like replace conditions; andWhere/orWhere append grouped clauses. Null equality maps to IS NULL. DELETE refuses an empty WHERE; UPDATE does not.

Execution builds a payload and resets the builder before contacting the provider. INSERT returns lastInsertId or null; SELECT fetches associative rows; UPDATE/DELETE return whether rowCount is positive. Bindings use PDO NULL/BOOL/INT/STR based on value. SqlExpression restricts update expressions to DEFAULT/CURRENT_TIMESTAMP; BoundValue forces literal values such as DEFAULT.

SELECT cache keys include SQL and serialized bindings, while DoNotCache on the class/parent disables reads. JOIN queries and active transactions bypass caching. Mutation invalidation uses the target table, scheduled with afterCommit on transactional providers. DatabaseCache stores array entries and an index in transient cache files; raw provider SQL does not automatically participate in invalidation.

DatabaseProvider lazily reuses global shared['DBEngine']['PDO']. Its ordinary DSN is DB_TYPE:host=...;dbname=..., so PostgreSQL install's 'postgresql' value and SQLite do not work there as configured. The framework installation test builds special DSNs and temporarily injects the PDO, which can hide this discrepancy until the next process.

Transactions use a WeakMap keyed by PDO, sharing nested callback frames across providers. Outermost begin/commit/rollback and nested SAVEPOINT/RELEASE/ROLLBACK preserve ordering. Successful nested callbacks merge into the outer frame; rolled-back callbacks are discarded. afterCommit runs immediately outside a frame. Failures in commit callbacks are raised after commit and do not roll back committed data; all callbacks are attempted. A PDO transaction started outside these frames is rejected.

Schema creation splits ColumnCreator definition construction, ColumnSQLBuilder SQL generation, TableSchemaProvider execution and TableRegistry ownership metadata. TableWizard uses InnoDB/utf8mb4 MySQL DDL and registry checks, not a general dialect abstraction. Headless mode creates bootstrap tables without registry access. DDL, registry writes and filesystem/package hooks are not globally atomic; see method traces for early returns and state retention.

Component reference

Clone this wiki locally