How to use the aiopg.sa.exc.ArgumentError function in aiopg

To help you get started, we’ve selected a few aiopg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aio-libs / aiopg / aiopg / sa / __init__.py View on Github external
"""Optional support for sqlalchemy.sql dynamic query generation."""
from .connection import SAConnection
from .engine import create_engine, Engine
from .exc import (Error, ArgumentError, InvalidRequestError,
                  NoSuchColumnError, ResourceClosedError)


__all__ = ('create_engine', 'SAConnection', 'Error',
           'ArgumentError', 'InvalidRequestError', 'NoSuchColumnError',
           'ResourceClosedError', 'Engine')


(SAConnection, Error, ArgumentError, InvalidRequestError,
 NoSuchColumnError, ResourceClosedError, create_engine, Engine)
github aio-libs / aiopg / aiopg / sa / connection.py View on Github external
async def _execute(self, query, *multiparams, **params):
        cursor = await self._get_cursor()
        dp = _distill_params(multiparams, params)
        if len(dp) > 1:
            raise exc.ArgumentError("aiopg doesn't support executemany")
        elif dp:
            dp = dp[0]

        result_map = None

        if isinstance(query, str):
            await cursor.execute(query, dp)
        elif isinstance(query, ClauseElement):
            compiled = query.compile(dialect=self._dialect)
            # parameters = compiled.params
            if not isinstance(query, DDLElement):
                if dp and isinstance(dp, (list, tuple)):
                    if isinstance(query, UpdateBase):
                        dp = {c.key: pval
                              for c, pval in zip(query.table.c, dp)}
                    else:
github aio-libs / aiopg / aiopg / sa / connection.py View on Github external
for compiled_params in compiled_parameters:
                    params = {key: (processors[key](compiled_params[key])
                                    if key in processors
                                    else compiled_params[key])
                              for key in compiled_params}
                    processed_parameters.append(params)
                post_processed_params = self._dialect.execute_sequence_format(
                    processed_parameters)

                # _result_columns is a private API of Compiled,
                # but I couldn't find any public API exposing this data.
                result_map = compiled._result_columns

            else:
                if dp:
                    raise exc.ArgumentError("Don't mix sqlalchemy DDL clause "
                                            "and execution with parameters")
                post_processed_params = [compiled.construct_params()]
                result_map = None

            await cursor.execute(str(compiled), post_processed_params[0])
        else:
            raise exc.ArgumentError("sql statement should be str or "
                                    "SQLAlchemy data "
                                    "selection/modification clause")

        return ResultProxy(self, cursor, self._dialect, result_map)
github aio-libs / aiopg / aiopg / sa / connection.py View on Github external
dp = dp[0]

        result_map = None

        if isinstance(query, str):
            await cursor.execute(query, dp)
        elif isinstance(query, ClauseElement):
            compiled = query.compile(dialect=self._dialect)
            # parameters = compiled.params
            if not isinstance(query, DDLElement):
                if dp and isinstance(dp, (list, tuple)):
                    if isinstance(query, UpdateBase):
                        dp = {c.key: pval
                              for c, pval in zip(query.table.c, dp)}
                    else:
                        raise exc.ArgumentError("Don't mix sqlalchemy SELECT "
                                                "clause with positional "
                                                "parameters")

                compiled_parameters = [compiled.construct_params(dp)]
                processed_parameters = []
                processors = compiled._bind_processors
                for compiled_params in compiled_parameters:
                    params = {key: (processors[key](compiled_params[key])
                                    if key in processors
                                    else compiled_params[key])
                              for key in compiled_params}
                    processed_parameters.append(params)
                post_processed_params = self._dialect.execute_sequence_format(
                    processed_parameters)

                # _result_columns is a private API of Compiled,
github aio-libs / aiopg / aiopg / sa / connection.py View on Github external
processed_parameters)

                # _result_columns is a private API of Compiled,
                # but I couldn't find any public API exposing this data.
                result_map = compiled._result_columns

            else:
                if dp:
                    raise exc.ArgumentError("Don't mix sqlalchemy DDL clause "
                                            "and execution with parameters")
                post_processed_params = [compiled.construct_params()]
                result_map = None

            await cursor.execute(str(compiled), post_processed_params[0])
        else:
            raise exc.ArgumentError("sql statement should be str or "
                                    "SQLAlchemy data "
                                    "selection/modification clause")

        return ResultProxy(self, cursor, self._dialect, result_map)