Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added cursor.description convenience and cursor.fetchmany #25

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

WilliamStam
Copy link

cursor.description

by the looks of it it should be available as cursor._cursor.description but anyways.. this is purely for convenience

see somone else was looking for this #19

cursor.fetchmany

fetchone, fetchall, fetchmany are the main function calls on the db handlers. just to bring this cool project in line with those... (the fact that i needed it has noooothing to do with it :P) i added this in

use case (fetch 2 rows at a time as a dict):

await cur.execute(query)
desc = [d[0] for d in  cur.description]
while True:
    rows = await cur.fetchmany(2)
    if not rows: # no rows left so we done
        break
    for row in rows: 
        print(dict(zip(desc, row))) # this is a dict of each row now

…ription so this is just a shortcut)

Added: cursor.fetchmany()
@WilliamStam
Copy link
Author

i have no clue why pycharm changed any of the other lines :( only things i added in are

@property
    def description(self):
        return self._cursor.description

and

async def fetchmany(self, *args, **kwargs):
    # block mainly happens when fetch triggered.
        return await self._loop.run_in_executor(self._thread_pool, self._cursor.fetchmany, *args, **kwargs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants