Debug Utilities¶
Debug and diagnostic utilities for NextORM.
Provides SQL debug logging and per-instance / global query statistics.
Example:
from nextorm import set_sql_debug, sql_debugging
set_sql_debug(True)
results = db.select(User).fetch_all()
# prints: >>> SELECT id, name FROM "user"
# params: []
with sql_debugging():
result = db.select(User).filter(User.id == 1).fetch_one()
- nextorm.debug.set_sql_debug(debug=True)[source]¶
Enable or disable global SQL debug logging.
When enabled, every SQL statement executed by
DatabaseorAsyncDatabaseis printed to stdout before execution. Usesql_debuggingas a context manager for scoped temporary debugging.Parameters¶
- debug:
Trueto enable (default),Falseto disable.
- Parameters:
debug (bool)
- Return type:
None
- class nextorm.debug.sql_debugging[source]¶
Bases:
objectContext manager that temporarily enables SQL debug output.
On exit the previous debug state is restored, regardless of exceptions:
with sql_debugging(): users = db.select(User).fetch_all() # debug logging is off again here
- class nextorm.debug.QueryStat[source]¶
Bases:
objectPer-query-string execution statistics.
Attributes¶
- count:
Number of times the query was executed.
- sum_time:
Total execution time in seconds.
- min_time:
Minimum single execution time (
infwhen count is 0).- max_time:
Maximum single execution time in seconds.
- avg_time:
Average execution time in seconds (computed property).
- nextorm.debug.global_stats: dict[str, QueryStat] = {}¶
Module-level global query statistics.
Populated by
merge_local_stats(); cleared byclear_global_stats().
- nextorm.debug.clear_global_stats()[source]¶
Clear the module-level
global_statsdictionary.- Return type:
None