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

Add use_batch_mode parameter to sqlalchemy create_engine #594

Closed
argolo opened this issue Feb 18, 2018 · 6 comments
Closed

Add use_batch_mode parameter to sqlalchemy create_engine #594

argolo opened this issue Feb 18, 2018 · 6 comments
Labels

Comments

@argolo
Copy link

argolo commented Feb 18, 2018

I would like to add use_batch_mode parameter or sqlalchemy create_engine. Is there something that allows this or can I work on a pull request? What would be the best approach in the case of pull request?

Source on use_batch_mode:

@pallets-eco pallets-eco deleted a comment from nirizr Mar 20, 2018
@nirizr
Copy link

nirizr commented Mar 20, 2018

Hi,
I also have that issue and I would also like it fixed, but in the meanwhile I found a simple work-around that helped me.

by accessing the engine's dialect you can manually set the member responsible for using the match_mode after the engine and dialect have been created. Assuming db = SQLAlchemy(flask_app), all you need to do is add the following line afterwards:

db.engine.dialect.psycopg2_batch_mode = True

@argolo
Copy link
Author

argolo commented Mar 20, 2018

Thank you, @nirizr ! I'll try that.

@moi90
Copy link

moi90 commented Aug 1, 2018

Thanks @nirizr !

However, Flask-SQLAlchemy should really allow passing keyword parameters to create_engine. The simplest solution would be a configuration key, right?

@nirizr
Copy link

nirizr commented Aug 1, 2018 via email

@grim7reaper
Copy link

Hi,

I also had the need to specify extra kwargs to the underlying call to create_engine (to be more specific, I needed to customize the isolation level).

To do so, I used the method apply_driver_hacks (documented here):

This method is called before engine creation and used to inject driver specific hacks into the options. The options parameter is a dictionary of keyword arguments that will then be used to call the sqlalchemy.create_engine() function.

What you need to do is to define your own class that overload this method:

class SQLAlchemyCustomized(flask_sqlalchemy.SQLAlchemy):
    def apply_driver_hacks(self, app, info, options):
        options['use_batch_mode'] = True
        super().apply_driver_hacks(app, info, options)

And then use your class instead of the default one:

# Replace "db = SQLAlchemy(app)" by
db = SQLAlchemyCustomized(app)

Hope that helps :)

@davidism davidism added the config label Feb 2, 2019
@rsyring
Copy link
Contributor

rsyring commented Mar 8, 2019

This will be resolved by: #166

@rsyring rsyring closed this as completed Mar 8, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

6 participants