Interface WriteContext

Context for write operations (run, batch).

const hooks: StorageHooks = {
onBeforeWrite: async (context) => {
// Add timestamp to all inserts
if (context.statement.toUpperCase().startsWith('INSERT')) {
context.metadata = { ...context.metadata, insertedAt: Date.now() };
}
return context;
}
};
interface WriteContext {
    operationId: string;
    startTime: number;
    adapterKind: string;
    metadata?: Record<string, unknown>;
    operation: "run" | "batch";
    statement: string;
    parameters?: StorageParameters;
    affectedTables?: string[];
    inTransaction?: boolean;
}

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: "run" | "batch"

Operation type (write operations only).

statement: string

SQL statement being executed.

Hooks can modify this to transform mutations.

parameters?: StorageParameters

Parameters for parameterized statements.

Hooks can modify this to transform parameters.

affectedTables?: string[]

Tables being modified by this write.

Used for cache invalidation and tracking.

inTransaction?: boolean

Whether this write is part of a transaction.