Get a cached prepared statement
Optionalparams: any[]Store a prepared statement in the cache
Optionalparams: any[]Record execution of a prepared statement
Check if a statement is cached
Optionalparams: any[]Clear all cached statements
Get cache statistics
Get all cached statements
Invalidate (remove) cache entries whose SQL references the given table.
Intended to be called by write paths (INSERT/UPDATE/DELETE/DDL) so cached
entries can't outlive schema/data changes for that table between TTL
expirations. Not automatically wired into every write in this codebase -
callers that write outside of QueryOptimizer should call this explicitly.
Remove expired entries
Tracks SQL statement usage (hit/miss counts, execution timings, last-used time) keyed by normalized SQL + params, with TTL-based expiry.
IMPORTANT — naming caveat: despite the name, this does not cache a real driver-level prepared-statement handle. None of the
Dialectimplementations insrc/dialects/**expose a separate prepare/execute split -query(sql, options)always receives the full SQL text and appliesoptions.replacements/options.bindper call (see e.g.sqlite/index.tsquery(), which callsconnection.prepare(sql)fresh on every invocation). So there is no reusable driver object for this class to hold onto; thecompiledfield on each entry is whatever metadata the caller passes toset()(by default just{}, or - seeQueryOptimizer.executeQuery()- a lightweight{ sql, paramCount }descriptor). In practice this class behaves as a query-usage/hit-count tracker with an optional metadata slot, not a real statement cache. It is kept under this name for backwards compatibility with existing callers/tests; treatgetStats()/hitCount/topStatementsas the reliable surface, and don't rely oncompiledholding an executable handle.Invalidation: entries expire via TTL (
options.ttl, default 1 hour). Since that alone can serve stale-shaped results after schema changes made via raw DDL,invalidateTable()is provided to drop entries referencing a given table name on write (e.g. from a caller's insert/update/delete path); it is not auto-wired to every write in this codebase, butQueryOptimizer. invalidateTableCache()calls it alongside the query-result cache.