Interface TransactionContext

Context for transaction operations.

const hooks: StorageHooks = {
onBeforeTransaction: async (context) => {
console.log(`Starting transaction ${context.operationId}`);
return context;
},
onAfterTransaction: async (context) => {
console.log(`Transaction ${context.operationId} committed`);
}
};
interface TransactionContext {
    operationId: string;
    startTime: number;
    adapterKind: string;
    metadata?: Record<string, unknown>;
    operation: "transaction";
    operationCount?: number;
    outcome?: "committed" | "rolled_back";
}

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

Operation type (transaction only).

operationCount?: number

Number of operations in this transaction (after completion).

outcome?: "committed" | "rolled_back"

Whether transaction was committed or rolled back.