コード例 #1
0
 def _join_criterion(self, left, right, join_type):
     if join_type.upper() == "AND":
         return left & right
     elif join_type.upper() == "OR":
         return left | right
     raise OperationalError(
         'join_type only support ("AND", "OR")')  # pragma: nocoverage
コード例 #2
0
ファイル: query.py プロジェクト: goryay/recipes1
 def __init__(self, *args, join_type=AND, **kwargs) -> None:
     if args and kwargs:
         newarg = QueryExpression(join_type=join_type, **kwargs)
         args = (newarg, ) + args
         kwargs = {}
     if not all(isinstance(node, QueryExpression) for node in args):
         raise OperationalError(
             "All ordered arguments must be QueryExpression nodes")
     self.children: Tuple[QueryExpression, ...] = args
     self.filters: Dict[str, Any] = kwargs
     if join_type not in {self.AND, self.OR}:
         raise OperationalError("join_type must be AND or OR")
     self.join_type = join_type
     self._is_negated = False
     self._annotations: Dict[str, Any] = {}
     self._custom_filters: Dict[str, Dict[str, Any]] = {}
コード例 #3
0
 async def db_delete(self) -> None:
     await self.close()
     conn = await asyncpg.connect(self._db_url)
     try:
         await conn.execute(f'DROP DATABASE IF EXISTS "{self.database}"')
     except Exception as e:  # pragma: nocoverage
         raise OperationalError(
             f"drop database {self.database}, error: {str(e)}")
     await conn.close()
コード例 #4
0
 async def db_create(self) -> None:
     conn = await asyncpg.connect(self._db_url)
     try:
         await conn.execute(
             f'CREATE DATABASE "{self.database}" OWNER "{self.user}"')
     except Exception as e:  # pragma: nocoverage
         raise OperationalError(
             f"create database {self.database}, error: {str(e)}")
     await conn.close()
コード例 #5
0
 async def translate_exceptions_(self, *args):
     try:
         return await func(self, *args)
     except asyncpg.SyntaxOrAccessError as exc:  # pragma: nocoverage
         raise OperationalError(exc)
     except asyncpg.IntegrityConstraintViolationError as exc:
         raise IntegrityError(exc)
     except asyncpg.InvalidTransactionStateError as exc:  # pragma: nocoverage
         raise TransactionManagementError(exc)
コード例 #6
0
ファイル: model.py プロジェクト: goryay/recipes1
    async def delete(self) -> int:
        """
        Deletes the current model object.

        :raises OperationalError: If object has never been persisted.
        """
        if not self._saved_in_db:
            raise OperationalError("Can't delete unpersisted record")
        mapper = self.get_mapper()
        return await mapper.delete(self)
コード例 #7
0
ファイル: query.py プロジェクト: goryay/recipes1
 def __or__(self, other) -> "QueryExpression":
     if not isinstance(other, QueryExpression):
         raise OperationalError(
             "OR operation requires a QueryExpression node")
     return QueryExpression(self, other, join_type=self.OR)