Available since: v4.0.0
dedupeTrace()
The dedupeTrace() function removes the entries of a query trace that repeat an earlier entry, and keeps the first copy of each. A statement can report the same edge, reference or link on more than one frame, and .responses() and .statements() join the frames as they were sent.
Import:
import { dedupeTrace } from 'surrealdb';Source: utils/dedupe-trace.ts
Function signature
function dedupeTrace(trace: QueryTrace): QueryTraceParameters
Parameter | Type | Description |
|---|---|---|
trace | QueryTrace | The trace to remove repeated entries from. It is not changed. |
Returns
QueryTrace - A trace that holds each entry once
Entries are identified by their record ids, and a link also by its field. Subscriptions are identified by their id. Variables are keyed by name, so they cannot repeat.
Example
const [response] = await db
.query('SELECT ->tagged->tag FROM post')
.trace('relations')
.responses();
if (response.success && response.trace) {
const unique = dedupeTrace(response.trace);
}See also
Tracing queries - Ask a query for its trace
Query.trace() - The method that asks for a trace