async def _execute_query_connection(self, query: str,
                                     connection: aiopg.Connection,
                                     **arguments: Any) -> None:
     query = self._prepare_for_interpolation(query=query,
                                             has_arguments=bool(arguments))
     async with connection.cursor() as cursor:
         await cursor.execute(query, self._wrap_json(arguments))
async def execute_query_all(connection: aiopg.Connection, query: str,
                            **arguments: Any) -> List[Dict[str, Any]]:
    # aiopg can work with psycopg2's cursor class
    async with connection.cursor(cursor_factory=RealDictCursor) as cursor:
        await cursor.execute(query, wrap_json(arguments))

        return await cursor.fetchall()
Beispiel #3
0
 async def get_by_username(conn: Connection, username: str):
     async with conn.cursor() as cur:
         await cur.execute(
             'SELECT id, first_name, middle_name, last_name, '
             'username, pwd_hash, is_admin FROM users WHERE username = %s',
             (username, ),
         )
         return User.from_raw(await cur.fetchone())
Beispiel #4
0
    async def execute(self,
                      conn: aiopg.Connection,
                      sql: str,
                      binds=None,
                      fetch=True):

        async with conn.cursor() as cursor:
            await cursor.execute(sql, binds)

            if fetch:
                result = await cursor.fetchall()
                return result
async def execute_query(connection: aiopg.Connection, query: str,
                        **arguments: Any) -> None:
    # aiopg can work with psycopg2's cursor class
    async with connection.cursor(cursor_factory=RealDictCursor) as cursor:
        await cursor.execute(query, wrap_json(arguments))
 async def _execute_query_connection(
     self, query: str, connection: aiopg.Connection, **arguments: Any,
 ) -> None:
     async with connection.cursor() as cursor:
         await cursor.execute(query, self._wrap_json(arguments))