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

Migration from Flask-SQLAlchemy Document? #7

Closed
dsully opened this issue Feb 12, 2017 · 3 comments
Closed

Migration from Flask-SQLAlchemy Document? #7

dsully opened this issue Feb 12, 2017 · 3 comments

Comments

@dsully
Copy link
Contributor

dsully commented Feb 12, 2017

Hi Derek - do you have a guide on migrating from Flask-SQLAlchemy to using SQLService?

I'm trying to wrap my head around what needs to be done, how the standard pattern of delaying engine creation can/should be done. For example:

import flask
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


def create_app(testing=False):
    app = flask.create_app(__name__, testing=testing)

    with app.app_context():
        db.init_app(app)

        log.info("SQLAlchemy URI: %s", app.config['SQLALCHEMY_DATABASE_URI'])

    from .api import api
    ...

Obviously the app context wouldn't be needed any longer. But the delayed connection is quite useful to handle production vs unit test configuration of the database.

@dgilland
Copy link
Owner

I actually have an example FlaskSQLService class that I showed in #3 which includes the late-binding approach for engine creation via the Flask extension proxy class.

It's not tested by me in any way so there may be bugs or edge cases that need to be addressed but that example should help you get started.

One day I may have enough time to formalize that example into a flask-sqlservice extension proper but until then, feel free to use it directly.

@dsully
Copy link
Contributor Author

dsully commented Feb 13, 2017

Great, thanks!

@dgilland
Copy link
Owner

Closing this for now. If you run into any other issues, feel free to re-open the issue or create a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants