dorm.contrib.prepared_stmts¶
Runtime control + introspection for PostgreSQL prepared statements.
API¶
dorm.contrib.prepared_stmts.set_threshold(threshold: int | None, *, alias: str = 'default') -> None
¶
Update the PREPARE_THRESHOLD for alias at runtime.
Pass an integer to enable caching after threshold executions
of the same SQL shape (psycopg's default is 5). Pass None
to disable prepared-statement caching entirely. The change
rebuilds the connection pool so existing checked-out
connections finish their work without disruption; the next
pool checkout uses the new threshold.
Side-effect: this re-invokes :func:dorm.configure to thread
the new value through to the backend wrapper. Other DATABASES
settings on alias are preserved.
dorm.contrib.prepared_stmts.active_prepared(*, alias: str = 'default') -> list[dict[str, Any]]
¶
Return the rows of pg_prepared_statements on alias.
Each row carries name / statement / prepare_time /
parameter_types / from_sql. The view is filtered to the
current backend session — multi-connection pools may need to
call this from a known session if reproducibility matters.
dorm.contrib.prepared_stmts.deallocate_all(*, alias: str = 'default') -> None
¶
Run DEALLOCATE ALL on the active connection for alias.
Useful after a migration that altered a column type — psycopg's
cached plan references the old type and the next execution
raises cached plan must not change result type. Calling
:func:deallocate_all from the post-migration hook clears the
cache without bouncing the pool.