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

Inconsistent connect behavior when using context manager #27

Open
cliandy opened this issue Apr 30, 2022 · 0 comments
Open

Inconsistent connect behavior when using context manager #27

cliandy opened this issue Apr 30, 2022 · 0 comments

Comments

@cliandy
Copy link

cliandy commented Apr 30, 2022

Somewhat confusingly, when calling connect() within a context manager, we get the Cursor but when not using a context manager, we get a Connection object. This is in contrast to behaviors with other db clients like sqlite3, SQLAlchemy, etc. and seems inconsistent. Curious to why we're not just returning self in __enter__()

def connect(*args, **kwargs):
"""
Constructor for creating a connection to the database.
>>> conn = connect('localhost', 8099)
>>> curs = conn.cursor()
"""
return Connection(*args, **kwargs)

pinot-dbapi/pinotdb/db.py

Lines 164 to 168 in dd8809c

def __enter__(self):
return self.cursor()
def __exit__(self, *exc):
self.close()

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

No branches or pull requests

1 participant