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

capture queryset as list of dictionaries. #102

Closed
wants to merge 2 commits into from

Conversation

soheildsh
Copy link

I have made an issue for this matter some hours ago: issue

I have tried to make a new method for the Cursors to fetch data and represent them as a list of dictionaries.
Each dictionary contains a row of data with the data columns as keys.

I believe that this feature is fully backward compatible and won't make a difficulty for previous users.

I also added some docs to use this method to readme file.

I would be honored to know your opinion on adding this feature to the package.

@cla-bot
Copy link

cla-bot bot commented Aug 21, 2021

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to [email protected]. For more information, see https://github.com/trinodb/cla.

Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add tests to test_dbapi.py. The test should contain duplicated column names case.

Also, here is git commit message guideline.
https://chris.beams.io/posts/git-commit/

Comment on lines +154 to +164
If you use debian or redhat linux distributions. you may need to install following to be able to install pip packages:

for Debian/Ubuntu/etc:
```
$ sudo apt-get install gcc python-dev libkrb5-dev
```

for RHEL/CentOS/etc:
```
$ sudo yum install gcc python-devel krb5-devel krb5-workstation python-devel
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend separating a PR since it's unrelated to dictionary change.

Comment on lines +469 to +472
def fetchjson(self):
columns = [col['name'] for col in self._query.columns]
rows = self.fetchall()
return [dict(zip(columns, item)) for item in rows]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we implement like this, there is less benefit because users can achieve the same thing easily with the existing code and cannot use in case of fetchone. Could you take a look at other library's implementation I shared in the issue?

@ebyhr
Copy link
Member

ebyhr commented Oct 28, 2022

Let me close this PR since there's no update for a while. Please feel free to reopen if you still want to continue the work.

@ebyhr ebyhr closed this Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants