Browse Source

Fix misleading documentation

IMO, you would normally interpret "creating and closing database connections all the time" as "creating and closing database connection on each request" as opposed to keeping persistent database connection for a lifetime of an application. However, the documentation is either misleading or "creating and closing database connection on each query" was implied. This, and the term "**application** context" itself makes it look like data placed into flask.g will be available for the following requests, which is not true at all. Let's make the documentation more explicit on this.
pull/2493/head
Dmitry Marakasov 7 years ago committed by GitHub
parent
commit
7e8efeb6e4
  1. 10
      docs/tutorial/dbcon.rst

10
docs/tutorial/dbcon.rst

@ -8,11 +8,11 @@ Let's continue building our code in the ``flaskr.py`` file.
You currently have a function for establishing a database connection with
`connect_db`, but by itself, it is not particularly useful. Creating and
closing database connections all the time is very inefficient, so you will
need to keep it around for longer. Because database connections
encapsulate a transaction, you will need to make sure that only one
request at a time uses the connection. An elegant way to do this is by
utilizing the *application context*.
closing database connections for each query is very inefficient, so you
will need to keep it around for the duratiob of a request. Because database
connections encapsulate a transaction, you will need to make sure that
only one request at a time uses the connection. An elegant way to do this
is by utilizing the *application context*.
Flask provides two contexts: the *application context* and the
*request context*. For the time being, all you have to know is that there

Loading…
Cancel
Save