Skip to content

Commit 3f3f278

Browse files
authored
Merge pull request #77 from tecladocode/jose/cou-141-update-rest-api-ebook-to-remove
2 parents 1fd9108 + 6302a16 commit 3f3f278

File tree

42 files changed

+47
-89
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+47
-89
lines changed

docs/docs/06_sql_storage_sqlalchemy/04_configure_flask_sqlalchemy/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ def create_app(db_url=None):
8989
api = Api(app)
9090

9191
# highlight-start
92-
@app.before_first_request
93-
def create_tables():
92+
with app.app_context():
9493
db.create_all()
9594
# highlight-end
9695

@@ -104,7 +103,7 @@ We've done three things:
104103

105104
1. Added the `db_url` parameter. This lets us create an app with a certain database URL, or alternatively try to fetch the database URL from the environment variables. The default value will be a local SQLite file, if we don't pass a value ourselves and it isn't in the environment.
106105
2. Added two SQLAlchemy values to `app.config`. One is the database URL (or URI), the other is a [configuration option](https://flask-sqlalchemy.palletsprojects.com/en/2.x/config/) which improves performance.
107-
3. Registered a function to run before our Flask app handles its first request. The function will tell SQLAlchemy to use what it knows in order to create all the database tables we need.
106+
3. When the app is created, tell SQLAlchemy to create all the database tables we need.
108107

109108
:::tip How does SQLAlchemy know what tables to create?
110109
The line `import models` lets SQLAlchemy know what models exist in our application. Because they are `db.Model` instances, SQLAlchemy will look at their `__tablename__` and defined `db.Column` attributes to create the tables.

docs/docs/06_sql_storage_sqlalchemy/04_configure_flask_sqlalchemy/end/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def create_app(db_url=None):
2525
db.init_app(app)
2626
api = Api(app)
2727

28-
@app.before_first_request
29-
def create_tables():
28+
with app.app_context():
3029
db.create_all()
3130

3231
api.register_blueprint(ItemBlueprint)

docs/docs/06_sql_storage_sqlalchemy/05_insert_models_sqlalchemy/end/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def create_app(db_url=None):
2525
db.init_app(app)
2626
api = Api(app)
2727

28-
@app.before_first_request
29-
def create_tables():
28+
with app.app_context():
3029
db.create_all()
3130

3231
api.register_blueprint(ItemBlueprint)

docs/docs/06_sql_storage_sqlalchemy/05_insert_models_sqlalchemy/start/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def create_app(db_url=None):
2525
db.init_app(app)
2626
api = Api(app)
2727

28-
@app.before_first_request
29-
def create_tables():
28+
with app.app_context():
3029
db.create_all()
3130

3231
api.register_blueprint(ItemBlueprint)

docs/docs/06_sql_storage_sqlalchemy/06_get_models_or_404/end/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def create_app(db_url=None):
2525
db.init_app(app)
2626
api = Api(app)
2727

28-
@app.before_first_request
29-
def create_tables():
28+
with app.app_context():
3029
db.create_all()
3130

3231
api.register_blueprint(ItemBlueprint)

docs/docs/06_sql_storage_sqlalchemy/06_get_models_or_404/start/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def create_app(db_url=None):
2525
db.init_app(app)
2626
api = Api(app)
2727

28-
@app.before_first_request
29-
def create_tables():
28+
with app.app_context():
3029
db.create_all()
3130

3231
api.register_blueprint(ItemBlueprint)

docs/docs/06_sql_storage_sqlalchemy/07_updating_models_sqlalchemy/end/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def create_app(db_url=None):
2525
db.init_app(app)
2626
api = Api(app)
2727

28-
@app.before_first_request
29-
def create_tables():
28+
with app.app_context():
3029
db.create_all()
3130

3231
api.register_blueprint(ItemBlueprint)

docs/docs/06_sql_storage_sqlalchemy/07_updating_models_sqlalchemy/start/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def create_app(db_url=None):
2525
db.init_app(app)
2626
api = Api(app)
2727

28-
@app.before_first_request
29-
def create_tables():
28+
with app.app_context():
3029
db.create_all()
3130

3231
api.register_blueprint(ItemBlueprint)

docs/docs/06_sql_storage_sqlalchemy/08_retrieve_list_all_models/end/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def create_app(db_url=None):
2525
db.init_app(app)
2626
api = Api(app)
2727

28-
@app.before_first_request
29-
def create_tables():
28+
with app.app_context():
3029
db.create_all()
3130

3231
api.register_blueprint(ItemBlueprint)

docs/docs/06_sql_storage_sqlalchemy/08_retrieve_list_all_models/start/app.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def create_app(db_url=None):
2525
db.init_app(app)
2626
api = Api(app)
2727

28-
@app.before_first_request
29-
def create_tables():
28+
with app.app_context():
3029
db.create_all()
3130

3231
api.register_blueprint(ItemBlueprint)

0 commit comments

Comments
 (0)