Skip to content

EloquentQueryRecorder

Records one EffectKind::Db entry per query on an Eloquent (illuminate/database) connection, via Connection::listen() — the Illuminate\Database\Events\QueryExecuted event Eloquent already fires after every query, rather than a PDO/DBAL-style decorator.

This event fires after the query has already run and its rows already returned to the caller through Eloquent’s own internal fetch path, which this recorder never sees — unlike RecordingPdo/ DoctrineRecordingMiddleware, there is nothing here to snapshot and hand back, so Effect::$result is always null. call carries the SQL, bindings and read/write type QueryExecuted exposes — no row data is available at this layer, which is a real, documented limitation of recording through Eloquent’s event rather than decorating its PDO connection, not an oversight.

Illuminate\Database\Connection::listen() is a no-op when the connection has no event dispatcher (Quiote\Database\Adapter\Eloquent\EloquentDatabase::connect() never sets one), so EloquentQueryRecorder::attach() installs a EloquentMinimalEventDispatcher first when the connection doesn’t already have one — an application-wired dispatcher, if present, is left alone and this recorder’s listener is simply added alongside whatever else is already listening.

Records into ActiveEffectLedger’s current ledger rather than a fixed one taken at construction: EloquentQueryRecorder::attach() runs once, at EloquentDatabase::connect(), and that connection is then recycled (not rebuilt) across every later request in a worker process — see ActiveEffectLedger’s own docblock for why a fixed ledger would be wrong past the connection’s first use. A query that runs with nothing currently active (e.g. before any request is being recorded) is simply not recorded.

A failing query never fires QueryExecuted (Eloquent only dispatches it after a successful run), so nothing here needs to guard against recording a failed call — that exclusion falls out of the event’s own contract.

final class EloquentQueryRecorder

SourceEloquentQueryRecorder.php
MethodDescription
attach(Connection $connection): voidAttaches the listener, once per connection.
fingerprintOf(string $sql): stringTrim + collapse internal whitespace runs; deliberately not full SQL normalization.
reset(): voidTest isolation: forgets which connections have been attached to.

public function attach(Connection $connection): void

Attaches the listener, once per connection.

The guard matters because connect() can run more than once for one logical connection — a reconnect after a dropped socket is the case a long-running worker exists to handle — and Connection::listen() appends unconditionally. Without it, every reconnect left one more listener and each query was recorded that many times into the ledger.

ParameterTypeDescription
$connectionConnection

public static function fingerprintOf(string $sql): string

Trim + collapse internal whitespace runs; deliberately not full SQL normalization.

ParameterTypeDescription
$sqlstring

Returns string

public static function reset(): void

Test isolation: forgets which connections have been attached to.