koxudaxi / py-data-api

A user-friendly client for AWS Aurora Serverless's Data API
https://koxudaxi.github.io/py-data-api
MIT License
40 stars 9 forks source link

optionally disable forced transactions when creating a cursor #75

Closed amaizr closed 3 years ago

amaizr commented 3 years ago

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
koxudaxi commented 3 years ago

@amaizr Thank you for creating this issue. I agree. :+1:

I have merged and released a new version as 0.4.22

Thank you very much

amaizr commented 3 years ago

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