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

Support Execute Chaining #279

Closed
1 task done
bendemott opened this issue Oct 31, 2022 · 2 comments · Fixed by #316
Closed
1 task done

Support Execute Chaining #279

bendemott opened this issue Oct 31, 2022 · 2 comments · Fixed by #316
Assignees
Labels
enhancement New feature or request

Comments

@bendemott
Copy link
Contributor

Describe the feature

Would it make more sense to return self from cursor.execute instead of TrinoResult

This would allow you to chain fetch operations

value = cursor.execute('SELECT 1').fetchone()[0]

In addition, __iter__ and rowcount can be implemented on the cursor itself - this seems to be how it is commonly done.

So with return self and __iter__ implemented the following would still be possible for convenience:

for row in cursor.execute('select * from system.runtime.nodes'):
    print(row) 

This is the behavior of psycopg3
The Python DBAPI2 spec doesn't specify the return value of execute so it's up to the driver to decide, but it is common in quite a few Python DBAPI2 drivers.

Describe alternatives you've considered

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!
@hovaesco
Copy link
Member

That's a great addition, @bendemott are you willing to submit a PR for this?

@bendemott
Copy link
Contributor Author

That's a great addition, @bendemott are you willing to submit a PR for this?

Yeah, I'll submit one soon, thanks.

@bendemott bendemott added the enhancement New feature or request label Dec 2, 2022
@bendemott bendemott self-assigned this Dec 2, 2022
@damian3031 damian3031 assigned damian3031 and unassigned bendemott Jan 4, 2023
This was referenced Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

3 participants