/** * SQLite Event Storage Implementation * * Implements EventStorage interface using SQLite database with the repository's existing DB client pattern. * Uses parameterized SQL queries and transactions for data integrity and performance. * * Features: * - Parameterized SQL queries to prevent SQL injection * - Transaction support for batch operations * - Automatic sequence number generation per world/chat using MAX(seq) + 1 * - Cascade delete via foreign keys to worlds/chats tables * - Efficient querying with indexed columns * - JSON storage for payload and metadata * - Duplicate event ID handling with INSERT OR IGNORE * * Cascade Delete Behavior: * - Foreign keys ensure events are deleted when their parent world is deleted * - Foreign keys ensure events are deleted when their parent chat is deleted * - PRAGMA foreign_keys = ON must be enabled (done in sqlite-schema.ts) * * Implementation Notes: * - Uses sqlite3 Database from the existing schema pattern * - Follows the promisify pattern used in sqlite-storage.ts * - Supports both time-based and sequence-based pagination * - Auto-increments sequence number using COALESCE(MAX(seq), 0) + 1 * - No separate sequence tracking table needed (removed event_sequences) * - Uses INSERT OR IGNORE to prevent UNIQUE constraint violations from duplicate event IDs * (can occur due to retries, multiple listeners, or error recovery) * * Changes: * - 2026-03-10: Added optional targeted event deletion by event ID for trim/edit cleanup without wiping an entire chat history. * - 2025-11-09: CRITICAL FIX - Let AUTOINCREMENT handle seq, don't set manually (was causing INSERT failures) * - 2025-11-03: Added INSERT OR IGNORE to handle duplicate event IDs gracefully * - 2025-11-06: Removed event_sequences table, use MAX(seq) + 1 for auto-increment */ import type { Database } from 'sqlite3'; import type { EventStorage } from './types.js'; export interface SQLiteEventStorageContext { db: Database; isInitialized: boolean; } /** * Create SQLite event storage context */ export declare function createSQLiteEventStorage(db: Database): Promise;