Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -399,20 +399,26 @@ Web service that computes the requested power of two.
text="2 ^ {} is {}".format(power, result))


async def init_app():
async def init_db(app):
"""Initialize a connection pool."""
app['pool'] = await asyncpg.create_pool(database='postgres',
user='postgres')
yield
app['pool'].close()


def init_app():
"""Initialize the application server."""
app = web.Application()
# Create a database connection pool
app['pool'] = await asyncpg.create_pool(database='postgres',
user='postgres')
# Create a database context
app.cleanup_ctx.append(init_db)
# Configure service routes
app.router.add_route('GET', '/{power:\d+}', handle)
app.router.add_route('GET', '/', handle)
return app


loop = asyncio.get_event_loop()
app = loop.run_until_complete(init_app())
app = init_app()
web.run_app(app)

See :ref:`asyncpg-api-pool` API documentation for more information.