koxudaxi/py-data-api

optionally disable forced transactions when creating a cursor

amaizr opened this issue · 2 comments

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

@amaizr
Thank you for creating this issue.
I agree. 👍

I have merged and released a new version as 0.4.22

Thank you very much

@koxudaxi thx 2 u for this great lib + fast release!