def _query(self, sql, **kwargs): """Send a query off to SQLAlchemy.""" if sql == 'START TRANSACTION': assert not self._trx_active self._trx_active = True elif sql == 'COMMIT': assert self._trx_active self._trx_active = False try: start = perf() query = self._sql_text(sql) result = self._exec(query, **kwargs) Stats.log_db(sql, perf() - start) return result except Exception as e: log.info("[SQL-ERR] %s in query %s (%s)", e.__class__.__name__, sql, kwargs) raise e
def _query(self, sql, is_prepared, **kwargs): """Send a query off to SQLAlchemy.""" if sql == 'START TRANSACTION': assert not self._trx_active self._trx_active = True elif sql == 'COMMIT': assert self._trx_active self._trx_active = False try: start = perf() query = self._sql_text(sql, is_prepared) if 'log_query' in kwargs and kwargs['log_query']: log.info("QUERY: {}".format(query)) result = self._basic_connection.execution_options(autocommit=False).execute(query, **kwargs) if 'log_result' in kwargs and kwargs['log_result']: log.info("RESULT: {}".format(result)) Stats.log_db(sql, perf() - start) return result except Exception as e: log.warning("[SQL-ERR] %s in query %s (%s)", e.__class__.__name__, sql, kwargs) raise e
async def _wrapper(*args, **kwargs): start = perf() result = await function(*args, **kwargs) Stats.log_db(args[1], perf() - start) return result