aws / amazon-redshift-python-driver

Redshift Python Connector. It supports Python Database API Specification v2.0.
Apache License 2.0
202 stars 72 forks source link

Feature request: `autocommit` as connector `__init__` property #203

Open avneeshn opened 6 months ago

avneeshn commented 6 months ago

Currently, to set autocommit to True, we have to explicitly run:

connection.autocommit = True

Is there a way to pass autocommit as a property to the connector constructor? Something like:

redshift_connector.connect({
   autocommit=True,
   **connection_params
})

We are trying to build an SQL client for our customers with Redshift as one of the underlying data-sources. It would be much cleaner this way avoiding unnecessary if-else conditioning.

Brooke-white commented 5 months ago

Hi @avneeshn , thank you for reaching out with this feature request. Would setting autocommit on the module level work for your use case? Setting autocommit=True on the module level would enable autocommit for subsequent connections. For example

import redshift_connector
redshift_connector.autocommit = True

redshift_connector.connect({ # autocommit is set to True, as specified on the redshift_connector module
   **connection_params
})

redshift_connector.connect({ # again, autocommit is set to True, as specified on the redshift_connector module
   **connection_params
})
avneeshn commented 5 months ago

That would not work for our case. We are creating and maintaining multiple connections so we need a connection-level autocommit property