How to use the aiopg.cursor.Cursor 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 / tests / test_connection.py View on Github external
async def test_default_event_loop(connect, loop):
    asyncio.set_event_loop(loop)

    conn = await connect(no_loop=True)
    cur = await conn.cursor()
    assert isinstance(cur, Cursor)
    await cur.execute('SELECT 1')
    ret = await cur.fetchone()
    assert (1,) == ret
    assert conn._loop is loop
github aio-libs / aiopg / tests / test_connection.py View on Github external
async def test_simple_select(connect):
    conn = await connect()
    cur = await conn.cursor()
    assert isinstance(cur, Cursor)
    await cur.execute('SELECT 1')
    ret = await cur.fetchone()
    assert (1,) == ret
github aio-libs / aiohttp-debugtoolbar / examples / extra_panels / extra_pgsql.py View on Github external
def __init__(self):
        self._queries = []
        self._total_time = 0
        # save original
        self._tmp_execute = Cursor.execute
github aio-libs / aiopg / aiopg / connection.py View on Github external
if not self.closed_cursor:
            warnings.warn(('You can only have one cursor per connection. '
                           'The cursor for connection will be closed forcibly'
                           ' {!r}.').format(self), ResourceWarning)

        self.free_cursor()

        if timeout is None:
            timeout = self._timeout

        impl = await self._cursor_impl(name=name,
                                       cursor_factory=cursor_factory,
                                       scrollable=scrollable,
                                       withhold=withhold)
        self._cursor_instance = Cursor(self, impl, timeout, self._echo)
        return self._cursor_instance
github aio-libs / aiopg / aiopg / sa.py View on Github external
_connection_factory=SAConnection,
                                    **kwargs))


@asyncio.coroutine
def create_pool(dsn=None, *, minsize=10, maxsize=10,
                loop=None, **kwargs):
    return (yield from base_create_pool(dsn,
                                        minsize=minsize,
                                        maxsize=maxsize,
                                        loop=loop,
                                        _connection_factory=SAConnection,
                                        **kwargs))


class SACursor(Cursor):

    def __init__(self, conn, impl, dialect):
        super().__init__(conn, impl)
        self._dialect = dialect

    @property
    def dialect(self):
        """sqlalchemy dialect, PGDialect_psycopg2() by default."""
        return self._dialect

    @asyncio.coroutine
    def execute(self, operation, parameters=()):
        if isinstance(operation, ClauseElement):
            assert parameters == (), ("Don't mix sqlalchemy clause "
                                      "and execution with parameters")
            compiled = operation.compile(dialect=self._dialect)