close connection in asyncpg example
This commit is contained in:
parent
b3b27cab34
commit
0860f84a39
|
@ -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