optionally disable forced transactions when creating a cursor
amaizr opened this issue · 2 comments
amaizr commented
Is your feature request related to a problem? Please describe.
In some cases (e.g. paginating a select) its useful to not force a transaction on each exec statement call which according to doc can be done by just excluding transaction id. Currently whenever we execute a statement w/o a transaction one is created for us.
Describe the solution you'd like
Add e.g. a connection arg that controls this automatic transaction behavior, e.g.
sqlalchemy.create_engine(
'postgresql+pydataapi://',
connect_args={
'resource_arn': 'my_cluster_arn',
'secret_arn': 'my_secret_arn',
'database': 'my_db',
'auto_transaction': False, # defaults to True
},
)
Describe alternatives you've considered
Patching py-data-api at runtime:
def pydataapi_cursor(self: pydataapi.dbapi.Connection) -> pydataapi.dbapi.Cursor:
# https://github.com/koxudaxi/py-data-api/blob/7f004883ff6c0ea3ca9285e69c71d07f45518693/pydataapi/dbapi.py#L135-L136
cursor = pydataapi.dbapi.Cursor(self._data_api)
self.cursors.append(cursor)
return cursor
pydataapi.dbapi.Connection.cursor = pydataapi_cursor