I've recently started using SQLAlchemy
and am trying to understand how the connection pool
and session
work in a web-application
I am building an API
using flask
.
__init__.py
engine = create_engine('mysql://username:password@localhost/my_database')
DBSession = sessionmaker(bind=engine)
views.py
@app.route('/books', methods = ['GET'])
def getBooks():
session = DBSession()
returnedBooks = session.query(BOOK).all()
session.close()
return something...
1) Firstly, if I don't explicitly close my session
object, will it automatically close after the request
has been processed?
2) When my app receives multiple requests
, are the multiple session
objects being created all linked to the single engine
object that was created in my __init__.py
file?
3) Are the session
objects being created in view.py
the connections
that the connection pool
holds? If so, and these weren't closed, then would new connections have to be made for subsequent requests?
4) Should I be using dispose()
at some point?