Interface QueryContext

Context for query operations (get, all, exec).

const hooks: StorageHooks = {
onBeforeQuery: async (context) => {
console.log(`Executing: ${context.statement}`);
return context; // or modified context
}
};
interface QueryContext {
    operationId: string;
    startTime: number;
    adapterKind: string;
    metadata?: Record<string, unknown>;
    operation: "get" | "all" | "exec";
    statement: string;
    parameters?: StorageParameters;
    affectedTables?: string[];
}

Hierarchy (view full)

Properties

operationId: string

Unique identifier for this operation (UUID v4).

Use for correlation in logs and traces.

startTime: number

Timestamp when operation started (ms since epoch).

adapterKind: string

Adapter kind (e.g., 'better-sqlite3', 'indexeddb', 'postgres').

metadata?: Record<string, unknown>

Custom metadata attached to this operation.

Hooks can read and modify this to pass data between hooks or to the calling code.

const results = await db.all(
'SELECT * FROM users WHERE id = ?',
[userId],
{ metadata: { skipCache: true, auditLevel: 'high' } }
);
operation: "get" | "all" | "exec"

Operation type (query operations only).

statement: string

SQL statement being executed.

Hooks can modify this to transform queries.

parameters?: StorageParameters

Parameters for parameterized queries.

Hooks can modify this to transform parameters.

affectedTables?: string[]

Tables referenced in this query (if detected).

Used for cache invalidation and tracking.