Merge pull request #532 from r0fls/example-asyncpg-close
close connection in asyncpg example
This commit is contained in:
commit
7f1e0557c9
|
@ -41,12 +41,14 @@ async def create_db(app, loop):
|
||||||
for i in range(0, 100):
|
for i in range(0, 100):
|
||||||
await conn.execute(f"""INSERT INTO sanic_post
|
await conn.execute(f"""INSERT INTO sanic_post
|
||||||
(id, content, post_date) VALUES ({i}, {i}, now())""")
|
(id, content, post_date) VALUES ({i}, {i}, now())""")
|
||||||
|
await conn.close()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
async def handler(request):
|
async def handler(request):
|
||||||
conn = await connect(**DB_CONFIG)
|
conn = await connect(**DB_CONFIG)
|
||||||
results = await conn.fetch('SELECT * FROM sanic_post')
|
results = await conn.fetch('SELECT * FROM sanic_post')
|
||||||
|
await conn.close()
|
||||||
return json({'posts': jsonify(results)})
|
return json({'posts': jsonify(results)})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user