app = Flask(__name__)
app.config.from_envvar('WRADMIN_SETTINGS')
+db_engine = create_engine(app.config['DATABASE_URI'])
+wradmin.model.init_model(db_engine)
def get_db():
- """Opens a new database connection if there is none yet for the
- current application context.
- """
+ """Opens a new database connection if there is none yet for the current application context."""
if not hasattr(g, 'db'):
- g.db_engine = create_engine(app.config['DATABASE_URI'])
- wradmin.model.init_model(g.db_engine)
- g.db = g.db_engine.connect()
+ g.db = db_engine.connect()
return g.db
@app.teardown_appcontext
def close_db(error):
- """Closes the database again at the end of the request."""
+ """Closes the database connection at the end of the request."""
if hasattr(g, 'db'):
g.db.close()