Use a Queries Session asynchronously within the Tornado framework.
The :pyTornadoSession <queries.TornadoSession>
class is optimized for asynchronous concurrency. Each call to :pyTornadoSession.callproc <queries.TornadoSession.callproc>
or :pyTornadoSession.query <queries.TornadoSession.query>
grabs a free connection from the connection pool and requires that the results that are r returned as a :pyResults <queries.tornado_session.Results>
object are freed via the :pyResults.free <queries.tornado_session.Results.free>
method. Doing so will release the free the Results object data and release the lock on the connection so that other queries are able to use the connection.
The following :py~tornado.web.RequestHandler
example will return a JSON document containing the query results.
import queries
from tornado import gen, web
class ExampleHandler(web.RequestHandler):
def initialize(self):
self.session = queries.TornadoSession()
@gen.coroutine
def get(self):
result = yield self.session.query('SELECT * FROM names')
self.finish({'data': result.items()})
result.free()
See the examples/index
for more :py~queries.TornadoSession
examples.
queries.tornado_session.TornadoSession
queries.tornado_session.Results