def execute(self, sql: str, params: typing.Mapping[str, typing.Any] = None):
"""
Executes SQL inside the transaction.
:param sql: The SQL to execute.
:param params: The parameters to excecute with.
"""
# re-paramatarize the query
logger.debug("Executing query {} with params {}".format(sql, params))
query, params = get_param_query(sql, params)
try:
results = await self.acquired_connection.execute(query, *params)
except (asyncpg.IntegrityConstraintViolationError,
asyncpg.exceptions.NotNullViolationError) as e:
raise IntegrityError(*e.args) from e
except asyncpg.ObjectNotInPrerequisiteStateError as e:
raise OperationalError(*e.args) from e
except (asyncpg.SyntaxOrAccessError, asyncpg.InFailedSQLTransactionError) as e:
raise DatabaseException(*e.args) from e
return results
评论列表
文章目录