Merge pull request #532 from r0fls/example-asyncpg-close

close connection in asyncpg example
This commit is contained in:
Raphael Deem
2017-03-08 18:51:44 -08:00
committed by GitHub

View File

@@ -41,12 +41,14 @@ async def create_db(app, loop):
for i in range(0, 100):
await conn.execute(f"""INSERT INTO sanic_post
(id, content, post_date) VALUES ({i}, {i}, now())""")
await conn.close()
@app.route("/")
async def handler(request):
conn = await connect(**DB_CONFIG)
results = await conn.fetch('SELECT * FROM sanic_post')
await conn.close()
return json({'posts': jsonify(results)})