# QueryRow

> Typed view-model for a single database query row consumed by the queries grid.

[API reference](/docs/api/index.md) › [Debug Core](/docs/extensions/debug-core/reference/index.md) › [Panel](/docs/extensions/debug-core/reference/panel/index.md) › [Db](/docs/extensions/debug-core/reference/panel/db/index.md) › QueryRow

| final class | `PHPForge\Debug\Panel\Db\QueryRow` |
| --- | --- |
| Implements | [`PHPForge\Debug\Storage\PanelRow`](/docs/extensions/debug-core/reference/storage/panelrow/index.md) |
| Source | [`src/Panel/Db/QueryRow.php`](https://github.com/php-forge/debug-core/blob/main/src/Panel/Db/QueryRow.php#L24) |

Typed view-model for a single database query row consumed by the queries grid.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`create()`](#method-create) static | Creates a captured statement with milliseconds as the common time unit. | `QueryRow` |
| [`extractType()`](#method-extractType) static | Returns the uppercase leading command verb of a statement, or `''` when it starts with no letter. | `QueryRow` |
| [`findBySequence()`](#method-findBySequence) static | Returns the row whose sequence matches the requested one exactly, or `null` when none does. | `QueryRow` |
| [`fromArray()`](#method-fromArray) static | Narrows one persisted statement of the database payload into a typed row. | `QueryRow` |
| [`fromTiming()`](#method-fromTiming) static | Builds a typed row from one resolved logger timing. | `QueryRow` |
| [`getDuplicate()`](#method-getDuplicate) | Returns the number of occurrences of this exact query. | `QueryRow` |
| [`getDuration()`](#method-getDuration) | Returns the execution time in milliseconds. | `QueryRow` |
| [`getQuery()`](#method-getQuery) | Returns the captured SQL statement. | `QueryRow` |
| [`getRows()`](#method-getRows) | Returns the driver-reported row count, or `null` when unavailable. | `QueryRow` |
| [`getSequence()`](#method-getSequence) | Returns the zero-based capture sequence. | `QueryRow` |
| [`getTimestamp()`](#method-getTimestamp) | Returns the capture timestamp in milliseconds since the Unix epoch. | `QueryRow` |
| [`getTrace()`](#method-getTrace) | Returns the captured source frames. | `QueryRow` |
| [`getTraceHash()`](#method-getTraceHash) | Returns the captured or derived caller hash. | `QueryRow` |
| [`getType()`](#method-getType) | Returns the extracted or explicitly captured command verb. | `QueryRow` |
| [`isExplainable()`](#method-isExplainable) | Returns whether the statement produces a useful EXPLAIN plan. | `QueryRow` |
| [`jsonSerialize()`](#method-jsonSerialize) | Returns the persisted row contract. | `QueryRow` |
| [`withDuplicate()`](#method-withDuplicate) | Returns a copy with the given duplicate count. | `QueryRow` |
| [`withRows()`](#method-withRows) | Returns a copy with the driver-reported row count, or `null` when the driver did not report one. | `QueryRow` |
| [`withSequence()`](#method-withSequence) | Returns a copy with the given sequence index. | `QueryRow` |
| [`withTrace()`](#method-withTrace) | Returns a copy with the given source frames and the caller hash derived from them. | `QueryRow` |
| [`withTraceHash()`](#method-withTraceHash) | Returns a copy with an explicitly captured caller hash without changing the source frames. | `QueryRow` |
| [`withType()`](#method-withType) | Returns a copy with an explicitly captured SQL command verb without changing the statement. | `QueryRow` |

## Method details

### create() <span id="method-create"></span>

```php
public static function create(string $query, float $duration, float $timestamp): self
```

Creates a captured statement with milliseconds as the common time unit.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$query` | `string` | Full SQL statement. |
| `$duration` | `float` | Execution time in milliseconds. |
| `$timestamp` | `float` | Capture timestamp in milliseconds since the Unix epoch. |

**Returns**

`self`: Row carrying the extracted command verb, without trace, sequence, or row count.

### extractType() <span id="method-extractType"></span>

```php
public static function extractType(string $sql): string
```

Returns the uppercase leading command verb of a statement, or `''` when it starts with no letter.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$sql` | `string` | SQL statement to inspect. |

**Returns**

`string`: Uppercase command verb, or `''`.

### findBySequence() <span id="method-findBySequence"></span>

```php
public static function findBySequence(list<self> $rows, string $seq): self|null
```

Returns the row whose sequence matches the requested one exactly, or `null` when none does.

The sequence is compared as a string, so a padded request such as `'02'` never matches sequence `2`.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rows` | `list<self>` | Captured rows to search. |
| `$seq` | `string` | Requested sequence number. |

**Returns**

`self|null`: Matching row, or `null` when the sequence was not captured.

### fromArray() <span id="method-fromArray"></span>

```php
public static function fromArray(mixed $data, string $path): self
```

Narrows one persisted statement of the database payload into a typed row.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$data` | `mixed` | Persisted statement, expected to be an object carrying the declared shape. |
| `$path` | `string` | JSON path of the statement, used to report a malformed payload. |

**Returns**

`self`: Row carrying every persisted statement field.

### fromTiming() <span id="method-fromTiming"></span>

```php
public static function fromTiming(array{info: string, category: string, timestamp: float, trace: array<int, array<string, mixed>>, level: int, duration: float, memory: int, memoryDiff: int, traceHash: string} $timing, string $type, int $seq, int|null $rows): self
```

Builds a typed row from one resolved logger timing.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$timing` | `array{info: string, category: string, timestamp: float, trace: array<int, array<string, mixed>>, level: int, duration: float, memory: int, memoryDiff: int, traceHash: string}` | Resolved timing. The duplicate count starts at `1`; [`DbSnapshot::capture()`](/docs/extensions/debug-core/reference/panel/db/dbsnapshot/index.md#method-capture) resolves the real occurrences across the request. |
| `$type` | `string` | Uppercase SQL command verb extracted from the statement. |
| `$seq` | `int` | Zero-based sequence index. |
| `$rows` | `int\|null` | Rows reported by the driver, or `null` when it reported none. |

**Returns**

`self`: Row with the timing scaled to milliseconds.

### getDuplicate() <span id="method-getDuplicate"></span>

```php
public function getDuplicate(): int
```

Returns the number of occurrences of this exact query.

**Returns**

`int`

### getDuration() <span id="method-getDuration"></span>

```php
public function getDuration(): float
```

Returns the execution time in milliseconds.

**Returns**

`float`

### getQuery() <span id="method-getQuery"></span>

```php
public function getQuery(): string
```

Returns the captured SQL statement.

**Returns**

`string`

### getRows() <span id="method-getRows"></span>

```php
public function getRows(): int|null
```

Returns the driver-reported row count, or `null` when unavailable.

**Returns**

`int|null`

### getSequence() <span id="method-getSequence"></span>

```php
public function getSequence(): int
```

Returns the zero-based capture sequence.

**Returns**

`int`

### getTimestamp() <span id="method-getTimestamp"></span>

```php
public function getTimestamp(): float
```

Returns the capture timestamp in milliseconds since the Unix epoch.

**Returns**

`float`

### getTrace() <span id="method-getTrace"></span>

```php
public function getTrace(): list<array<string, mixed>>
```

Returns the captured source frames.

**Returns**

`list<array<string, mixed>>`: Captured backtrace frames.

### getTraceHash() <span id="method-getTraceHash"></span>

```php
public function getTraceHash(): string
```

Returns the captured or derived caller hash.

**Returns**

`string`

### getType() <span id="method-getType"></span>

```php
public function getType(): string
```

Returns the extracted or explicitly captured command verb.

**Returns**

`string`

### isExplainable() <span id="method-isExplainable"></span>

```php
public function isExplainable(): bool
```

Returns whether the statement produces a useful EXPLAIN plan.

Only single table-touching DML verbs (`SELECT`, `INSERT`, `UPDATE`, `DELETE`, `REPLACE`, `WITH`) qualify;
multi-statement text and other verbs either error or return noise under EXPLAIN.

**Returns**

`bool`: `true` when the statement can be explained; `false` otherwise.

### jsonSerialize() <span id="method-jsonSerialize"></span>

```php
public function jsonSerialize(): array<string, mixed>
```

Returns the persisted row contract.

**Returns**

`array<string, mixed>`: Row fields in their persisted order.

### withDuplicate() <span id="method-withDuplicate"></span>

```php
public function withDuplicate(int $duplicate): self
```

Returns a copy with the given duplicate count.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$duplicate` | `int` | Number of times the exact same statement was emitted in this request (`>= 1`). |

**Returns**

`self`: Copy carrying the duplicate count.

### withRows() <span id="method-withRows"></span>

```php
public function withRows(int|null $rows): self
```

Returns a copy with the driver-reported row count, or `null` when the driver did not report one.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$rows` | `int\|null` | Rows returned or affected, or `null` when the driver reported none. |

**Returns**

`self`: Copy carrying the row count.

### withSequence() <span id="method-withSequence"></span>

```php
public function withSequence(int $sequence): self
```

Returns a copy with the given sequence index.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$sequence` | `int` | Zero-based sequence index assigned by the panel. |

**Returns**

`self`: Copy carrying the sequence index.

### withTrace() <span id="method-withTrace"></span>

```php
public function withTrace(list<array<string, mixed>> $trace): self
```

Returns a copy with the given source frames and the caller hash derived from them.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$trace` | `list<array<string, mixed>>` | Argument-free source frames. |

**Returns**

`self`: Copy carrying the frames and their derived caller hash.

### withTraceHash() <span id="method-withTraceHash"></span>

```php
public function withTraceHash(string $traceHash): self
```

Returns a copy with an explicitly captured caller hash without changing the source frames.

Call after [`QueryRow::withTrace()`](/docs/extensions/debug-core/reference/panel/db/queryrow/index.md#method-withTrace) to preserve a logger-provided hash instead of the derived hash.
A subsequent `withTrace()` call derives the hash again.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$traceHash` | `string` | Captured caller hash, or `''` when no caller was captured. |

**Returns**

`self`: Copy carrying the hash unchanged.

### withType() <span id="method-withType"></span>

```php
public function withType(string $type): self
```

Returns a copy with an explicitly captured SQL command verb without changing the statement.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$type` | `string` | Captured command verb, preserved without normalization. |

**Returns**

`self`: Copy carrying the verb unchanged.