We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
# Execute a query db.User.get(id=123) # Get statistics stats = db.local_stats[db.last_sql] # Print it logger.debug( "QUERY STATS:\nTook {avg_time} second(s), Executed {db_count} time(s).".format( avg_time=stats.avg_time, db_count=stats.db_count ) )
db.last_sql returns last SQL query. db.local_stats returns a dictionary of QueryStat Objects, the keys are the SQL queries.
db.last_sql
db.local_stats
QueryStat
QUERY STATS: Took 1.4071071147918701 second(s), Executed 2 time(s).
As one-liner this would be equivalent:
logger.debug("QUERY STATS:\nTook {s.avg_time}, Executed {s.db_count} time(s).".format(s=db.local_stats[db.last_sql]))