Open thedrow opened 6 years ago
oh. Ya query got removed as it has weird behavior and didnt work as people thought. So this is mostly a documentation issue.
So how do I create a cursor?
async with pool.transaction() as t:
async with t.cursor("SELECT ...") as cursor:
...
https://github.com/CanopyTax/asyncpgsa/blob/master/asyncpgsa/connection.py#L110
For some reason I'm getting a Cursor object and not a CursorIterator so it errors on missing __aiter__
when I do async for row in cursor
.
The example you gave errors with AttributeError: __aexit__
...
@thedrow Hey. Sorry about this, it looks likes cursors changed how they work in asyncpg. Can you reference this: https://github.com/MagicStack/asyncpg/blob/master/docs/api/index.rst#cursors
and use cursors that way? I will try adding tests for cursor support soon when I get time. But hopefully that should work.
basically
cur = await con.cursor('select ...')
await cur.forward(10) # move cursor ahead 10 rows
print(await cur.fetchrow()) # get a single row
print(await cur.fetch(5)) # get 5 rows```
actually it looks like this was my fault in telling you async with
but it should actually be async for
async with pool.transaction() as t:
async for record in t.cursor("SELECT ..."):
...
I will gladly accept PR's that fix the documentation on this subject :)
I did exactly as you said. I get a Cursor. Not a CursorIterator for some reason.
@thedrow can you try this on just asyncpg? what object does it give you? a cursoriterator?
I'll do so shortly :)
I have declared a connection pool and tried to call cursor like so:
The query() method is currently missing. It might be a documentation problem though.